如何保存从1日的活动传递给第二个活动意图数据 [英] how to save intent data passed from 1st activity to 2nd activity

查看:86
本文介绍了如何保存从1日的活动传递给第二个活动意图数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Myactivity这是从以前的活动获取意图数据。意图数据通过活动的纺丝器发送。我想微调的意图这个数据保存到Myactvity。当我通过下一个活动的菜单选项进入Myactivity意图数据要坚持。

I have Myactivity which is getting the intent data from the former activity. The intent data is sent through a spinner of the activity. I want to save this intent data of the spinner to the Myactvity. the intent data should persist when i enter the Myactivity through menu option of next activity.

推荐答案

在你第一次活动1

                Intent myintent= new Intent(FirstActivity.this,SecondActivity.class);
                myintent.putExtra("Name", "your String");
                startActivity(myintent);

在第二活性2

        Intent myintent = getIntent();
        if(null!=myintent.getExtras()){
        String Name= myintent.getExtras().getString("Name");        
        Toast.makeText(getApplicationContext(),""+Name,12).show();                              

        }
        else
        {
            Toast.makeText(getApplicationContext(),"No Recor Here..",12).show();

        }

如共享preferences [2]
在你第一次ActivityA

like SharedPreferences[2] in your First ActivityA

           Intent myintent= new Intent(FirstActivity.this,SecondActivity.class);
            SharedPreferences spref = this.getSharedPreferences("mynotifyid", MODE_WORLD_WRITEABLE);
            SharedPreferences.Editor spreedit = spref.edit();
            spreedit.putString("Name1", str1.toString());   
            spreedit.putString("Name2", str2.toString());   
            spreedit.putString("Name3", str3.toString());   
            spreedit.putString("Name4", str4.toString());   
            spreedit.commit();
            startActivity(myintent);

在你的第二个ActivityB

in your Second ActivityB

        SharedPreferences spref = context.getSharedPreferences("mynotifyid", Context.MODE_WORLD_WRITEABLE);
        String str1 = spref.getString("Name1","");
        String str2 = spref.getString("Name2","");
        String str3 = spref.getString("Name3","");
        String str4 = spref.getString("Name4","");

为您节省对象的目的使用共享preferences

for your object saving purpose use SharedPreferences

这篇关于如何保存从1日的活动传递给第二个活动意图数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆