简体   繁体   English

如何保存Intent状态

[英]How to save a state of on Intent

I have three activities. 我有三个活动。 A, B and C. I press a button to open the B through startActivity(intent) . A,B和C。我按一个按钮通过startActivity(intent)打开B。 From the BI pass data back to A through intent.putExtra() and then, from AI get the data through getIntent . 从BI通过intent.putExtra()将数据传递回A,然后从AI通过getIntent获得数据。 I'm putting this data in a String on my A. The problem is that when I try to do the same with C. The data that I get from the B disappears. 我将这些数据放在A上的字符串中。问题是,当我尝试对C进行相同操作时,我从B获得的数据消失了。 My question is: How can I get data from two activities? 我的问题是:如何从两个活动中获取数据?

Do you want to pass data from activity B to C via A? 您是否要通过活动A将数据从活动B传递到C?

If its that what I understand,then follow the foll steps: 如果它是我所了解的,那么请遵循以下步骤:

Calling A from B: 从B呼叫A:

Intent i=new Intent(getApplicationContext(),A.class);
i.putExtra("key","value");
startAtivity(i);  

Fetching data from intent in class A: 从类A中的意图中获取数据:

Bundle extras = getIntent().getExtras();
String value=extras.getString("key");

Passing same data to activity C from class A: 将相同的数据从类A传递到活动C:

Intent i=new Intent(getApplicationContext(),C.class);
i.putExtra("key",value);
startAtivity(i);

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM