简体   繁体   English

是否需要从主屏幕小部件转到mainActivity中的片段?

[英]Need to go to a fragment in my mainActivity from a Home Screen Widget?

Need to go to a Fragment in my MainActivity from a home screen Widget . 需要从主屏幕Widget转到我的MainActivityFragment In my MainActivity The first view is a ListView in a Fragment , there is an add button to enter in some data and this add button opens a Fragment that has some EditText in it and on save it adds the entered data into the ListView back in the main Fragment so here's my problem. 在我的MainActivity ,第一个视图是FragmentListView ,有一个添加按钮可输入一些数据,此添加按钮将打开其中包含一些EditTextFragment ,并保存EditText输入的数据添加到ListView中。主要Fragment所以这是我的问题。 I can get back to the MainActivity by calling 我可以通过致电回到MainActivity

Intent details = new Intent(context, MainActivity.class); 
details.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(details);

and that gets me back to the main Fragment with the Listview but how could I get back to the Fragment that is called to enter the data on a Button click in the MainActivity . 然后用Listview回到主Fragment ,但是如何返回在MainActivity单击Button来输入数据的Fragment From the home screen Widget I would like to open the enter data Fragment not the main Fragment ? 从主屏幕Widget我想打开输入数据Fragment不是主Fragment

Define the Intent as Intent定义为

Intent details = new Intent(context, MainActivity.class); 
details.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
details.putExtra("data", "data");
context.startActivity(details);

In your MainActivity 's onCreate() method: 在您的MainActivityonCreate()方法中:

if(getIntent().hasExtra("data")){

  // call Enter data Fragment (via FragmentManager)

}
else{

  // call ListView Fragment (via FragmentManager)

}

Try this. 尝试这个。 This should work. 这应该工作。

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

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