从 Activity B 的 Fragment B 中点击 “按钮” 跳转到 MainActivity 的 Fragment A

来源:互联网 发布:财务报表软件免费版 编辑:程序博客网 时间:2024/05/22 10:35
 Fragment  B 中使用的

public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_stroll:// 随便逛逛
Intent intent = new Intent(getActivity(), MainActivity.class);
intent.putExtra("mk", "1");// 发送标志,使之能跳到首页
getActivity().startActivity(intent);
break;
}
}



MainActivity 中使用的

// 接收"随便逛逛"传过来的值显示首页
Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
mar = intent.getStringExtra("mk");
if (mar != null ) {
setCurPoint(0);// 显示Fragment A页面
}
}


这样写在定制的安卓系统中能实现,但是在原生安卓或者改动不大的安卓系统中就报错,如下:

java.lang.IllegalStateException: API cannot be called whiile activity is paused
at  android.nfc NfcAdapter.enforceResumed (NfcAdapter)
at  android.nfc.NfcAdapter.enableForegroundNdefPush
at com.项目名称.ui.MainActivity.sendNfcCode
at com.项目名称.ui.MainActivity.setCurPoint
at com.项目名称.ui.MainActivity.onNewIntent
at  adnroid.app.Instrumentation .callActivityOnNewIntent



希望懂的大大不吝教育,谢谢!
0 0
原创粉丝点击