[英]How to send data from the 5th activity to the 1st activity?
我正在使用 5 个活动。 我从活动 1 移动到活动 2,从活动 2 到活动 3,从活动 3 到活动 4,从活动 4 到活动 5。 活动 2 将数据传送到活动 3,这样活动 5 接收活动 2、活动 3、活动 4 的数据,然后将所有数据发送到活动 1。
我的第一个活动
I{
Intent i= new Intent(firstactivity.this, secondactivity.class);
startActivityForResult(i, 10);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 10) {
String a= data.getStringExtra("Value1");
String b= data.getStringExtra("Value2");
String c= data.getStringExtra("Value3");
String d= data.getStringExtra("Value4");
String showall = a+", "+b+", "+c+", "+d;
address.setText(showall);
}
我的第二个活动
Intent intent = new Intent(secondactivity.this, thirdactivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
intent.putExtra("Value1", firstvalue);
startActivity(intent);
我的第五个活动
Intent intent = new Intent(fourthactivity.this, fifthactivity.class);
intent.putExtra("Value1", geta);
intent.putExtra("Value2", getb);
intent.putExtra("Value3", getc);
intent.putExtra("Value4", getd);
intent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
setResult(10);
finish();
试试下面:
Intent intent = new Intent(fifthactivity.this, firstactivity.class);
intent.putExtra("Value1", geta);
intent.putExtra("Value2", getb);
intent.putExtra("Value3", getc);
intent.putExtra("Value4", getd);
intent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT|Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
startActivity(intent);
然后在您的onNewIntent
onCreate
(以防活动被破坏)或onNewIntent
(如果您的活动仍在运行但您将其置于最前面并使用新意图更新它)中处理您firstactivity
//A simple approach to solve this issue is to use sharedpreferences
//store value from activity five
getsharedpreferences('temp','MODE_PRIVATE').edit().clear().putString('values','new value').apply();
//get values from shared preferences if its available
String value 5 = getsharedpreferences('temp','MODE_PRIVATE').getString('values','nil');
getsharedpreferences('temp','MODE_PRIVATE').edit().clear();
第一次活动
static ArrayList<String> arlist=new ArrayList<String>();
arlist.add("value");
arlist.add("value1");
arlist.add("value2");
在第二个活动中
ActivityOne.arlist
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.