基本上我的应用程序有 2 个活动。说 "A" 和 "B" 。A 启动 B。
Activity B 播放音乐,也有通知。
案例 1:当视图仍在活动 B 上时,我按下主页按钮,然后单击通知,活动 B 以完整的视图打开并播放音乐(因为在清单中我使用的是 android:launchMode= “singleTop”,因此没有创建另一个活动实例)这部分是根据需要......但是
案例2:当视图在活动B上并且我按下返回按钮时,活动A出现然后我点击通知,活动B打开,视图丢失并且音乐也停止(不需要)......我猜测它会发生,因为当我按下后退按钮时,活动被破坏,所以我必须以编程方式恢复它的视图吗?所以要恢复它的视图我覆盖了两种方法.....
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
// Save UI state changes to the savedInstanceState.
// This bundle will be passed to onCreate if the process is
// killed and restarted.
savedInstanceState.putBoolean("boolMusicPlaying", boolMusicPlaying);
savedInstanceState.putInt("swapnumber", swapnumber);
savedInstanceState.putString("seekbarprogress", progress2);
savedInstanceState.putInt("position.seekbar",seekbar.getProgress());
savedInstanceState.putString("seekmaxString", max2);
savedInstanceState.putInt("seekmaxInt",seekMax);
savedInstanceState.putParcelableArrayList("songfetails",songdetails);
super.onSaveInstanceState(savedInstanceState);
}
//make a note ....even if i don't override onDestroy() and don't call on SaveInstanceState explicitly, then too i am not getting any desired effect.......
@Override
public void onDestroy()
{ Bundle savedState = new Bundle();
onSaveInstanceState(savedState);//because of this line....the app is crashing......
super.onDestroy();
}
但它没有帮助......在创建时我正在检查保存的实例是否为空......相应地创建视图......(即从保存的实例或新鲜的)但它没有t帮助...这条线也在崩溃...onSaveInstanceState(savedState);
即使我不覆盖 ondestroy() 并从任务杀手手动终止应用程序,然后尝试打开活动 B,那么保存的实例也应该正常工作,因为 OnSaveInstanceState 方法将被自动调用,对吧? ?请帮忙