简体   繁体   English

如何保存从第一个活动传递到第二个活动的意图数据

[英]how to save intent data passed from 1st activity to 2nd activity

I have Myactivity which is getting the intent data from the former activity. 我有Myactivity,它正在从以前的活动中获取意图数据。 The intent data is sent through a spinner of the activity. 意图数据是通过活动的微调器发送的。 I want to save this intent data of the spinner to the Myactvity. 我想将微调器的意图数据保存到Myactvity。 the intent data should persist when i enter the Myactivity through menu option of next activity. 当我通过下一个活动的菜单选项进入Myactivity时,意图数据应保持不变。

in your First Activity1 在您的第一个活动1

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

in Second Activity2 在第二活动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();
}

like SharedPreferences[2] in your First ActivityA 就像您的第一个ActivityA中的SharedPreferences [2]

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);

in your Second ActivityB 在您的第二个活动B中

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","");

for your object saving purpose use SharedPreferences 为了您的对象保存目的,使用SharedPreferences

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从第二活动到第一活动获取数据 - How to get data from 2nd Activity to 1st Activity 从第一个活动中获取意图后如何刷新第二个活动 - How to refresh 2nd activity after intent from 1st activity 按下后如何将数据从第二个活动传递到第一个活动? - android - How to pass data from 2nd activity to 1st activity when pressed back? - android 将第1个活动的值传递给android中的第2个活动 - Pass the value from 1st activity to 2nd activity in android 从第一个活动转到第二个活动时出错 - error when going from 1st activity to 2nd activity 如何在不按后退按钮和关闭按钮的情况下将数据从第二个活动传递到第一个(弹出窗口)? - How to pass data from 2nd activity to 1st (Popup) without press back button and close button? 如何在第一个活动中调用第二个活动值? - how to call 2nd activity value in 1st activity? 从Android中的第一个应用程序开始第二个应用程序的活动 - Start Activity of 2nd app from 1st app in android 在不丢失更新数据的情况下将第二个活动的价值保存到第一个活动 - Saving value from 2nd activity to 1st without losing the updated data 如何从第一个活动到第二个活动检索插入数据库中的图片? - How to retrieve a picture inserted in the database from 1st to 2nd activity?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM