我已经在我的Activity中实现了NFC 前台调度。代码工作正常,当 NFC 标签靠近我的手机时,就会调用。onNewIntent(Intent intent)
现在,我想在调用时显示一个片段(MyFragment.java)onNewIntent(Intent intent)
。Fragment类中resolveIntent(Intent intent)
定义了方法。
这是我的Activity的一些代码:
public class MainActivity extends Activity{
…
@Override
public void onNewIntent(Intent intent) {
super.onNewIntent(intent);
FragmentManager fragmentManager = activity.getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
//How to pass the 'intent' to MyFragment?
MyFragment fragment = new MyFragment();
fragmentTransaction.replace(R.id.placeholder, fragment, fragmentName);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
}
}
MyFragment.java的代码
public class MyFragment extends Fragment{
…
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
...
}
@Override
public void onResume(){
super.onResume();
//How to get 'intent' here
resolveIntent(intent);
}
private void resolveIntent(Intent intent){
...
}
}
我的问题是如何将intent
from传递onNewIntent(Intent intent)
给MyFragment以便我可以处理MyFragment in 中的意图onResume()
?