[英]How to set an intent so that I can send a data to the second activity and from there to the third activity?
I get input from user in first activity and send that to a second activity. 我在第一个活动中从用户那里得到输入,然后将其发送到第二个活动。 From the second activity, using the user input, I fetch data from the db and want to send that data to a third activity.
在第二个活动中,使用用户输入,我从数据库中获取数据,并希望将该数据发送到第三个活动。 How do I give the intent from the second activity to the third activity?
从第二个活动到第三个活动,我如何给出意图?
Presumably you are starting each activity using an Intent in which case you could pass data as an extra. 大概您是使用Intent开始每个活动的,在这种情况下,您可以额外传递数据。
Intent i = new Intent(FirstActivity.this, SecondActivity.class);
i.putExtra("user_input_key", "user_input");
startActivity(i);
In the second activity onCreate 在第二个活动中,onCreate
Bundle extras = getIntent().getExtras();
if (extras != null) {
String userInput = extras.getString("user_input_key");
//Once activity starts use this string to get data from DB and put/get extra in the same way
}
You shouldn't be passing the intent between activities. 您不应该在活动之间传递意图。 Identify exactly what you want to pass between activities and put that data in the intent as an extra and retrieve that data in the new Activity onCreate.
准确确定您要在活动之间传递的内容,并将这些数据作为额外的意图放入并在新的Activity onCreate中检索该数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.