[英]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
转到我的MainActivity
的Fragment
。 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
,第一个视图是Fragment
的ListView
,有一个添加按钮可输入一些数据,此添加按钮将打开其中包含一些EditText
的Fragment
,并保存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: 在您的MainActivity
的onCreate()
方法中:
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.