简体   繁体   English

如何设置一个意图,以便我可以将数据发送到第二个活动,然后从那里发送到第三个活动?

[英]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.

相关问题 将数据从第二个活动传递到第三个活动 - Passing data from second activity to third activity 如何根据第一活动数据(单击单选按钮)从第二活动转到第三活动或第四活动? - How to go from second activity to third activity or fourth activity based on first activity data (Radio button clicked)? 如何通过意图将数据从当前活动发送到新活动? - How to send data to new activity from current activity via intent? 如何使用arrayAdapter中的intent进入第三个活动? - How do I use intent from arrayAdapter to go into a third activity? 当我打算获取 arrayList 的数据时,如何在第二个活动和 setText 和 Image 中获取这些数据? - When I intent the arrayList's data, and how can I get those data in the second activity and setText and Image? 将活动中的数据发送到第三方服务 - Send data from an activity to a third part service 如何将意图数据设置为当前活动editText? - How do I set intent data to current activity editText? 第二个活动无法从意图中读取 getExtras - Second activity can't read getExtras from intent 如何从 Activity 获取 Intent 数据到 Fragment - How to get Intent Data from Activity into Fragment 我如何通过使用Intent从Android中的另一个常规活动中调用特定的选项卡活动 - How can i call a specific tab activity from another regular activity in android by using intent
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM