目前,在我的代码中,我使用的活动每次都没有引入布局。我使用以下标志:不确定为什么它不会通过。这是我的代码:
Intent intent = new Intent(getActivity(), MyActivity.class);
intent.putExtra(MyActivity.EXTRA_GROUPID, convo.getGroupID());
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
这是我调用的布局:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mine);
App.getComponent().inject(this);
App.subscribe(this);
if (getIntent() == null) {
Timber.e("Missing intent");
finish();
return;
}
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
if (getSupportActionBar() != null) {
getSupportActionBar().setTitle(R.string.message_add_to_title);
}
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().hide();
audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
isAnswering = getIntent().getBooleanExtra(EXTRA_ANSWERING, false);
isFromNotification = getIntent().getBooleanExtra(EXTRA_IS_FROM_NOTIFICATION, false);
GroupID = getIntent().getStringExtra(EXTRA_GROUPID);
if (TextUtils.isEmpty(GroupID)) {
finish();
return;
}
myConvo = convoRepository.get(GroupID);
if (myConvo == null) {
finish();
return;
}
if (savedInstanceState == null) {
// TODO remove constructor arguments
myFragment = new RoomFragment(myConvo.getAllUsers().size(), isFromNotification);
if (myFragment != null) {
getSupportFragmentManager().beginTransaction()
.add(
R.id.my_fragment_container,
myFragment,
BaseFragment.class.getSimpleName()
).commit();
if (!isFromNotification) {
checkPermissionAndJoin();
} else {
// Make sure to sure speaker state
audioManager.setSpeakerphoneOn(FSM.getInstance().getUIState().isSaveSpeakerOnState());
}
} else {
finish();
}
}
}
不确定是什么原因导致布局被抑制,当它应该每次都启动时。在我的清单中,我已将launchmode添加为singleTop。我应该以某种方式在停止或ondestroy上清除活动,以便之前的实例不会保持打开状态吗?