【发布时间】:2016-06-25 22:47:14
【问题描述】:
当单击退出我的应用程序并调用 onPause() 的主页按钮时, 然后我从锁屏通知重新打开我的应用程序,即使活动最初从未被破坏,也会调用 onCreate() 。这导致用户必须按后退键 2 次以上才能退出应用程序并销毁所有活动。 用户只需按一次返回键即可退出应用程序。 这只发生在我使用主页按钮退出应用程序时。 heres a video demo of the bug
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
protected void onResume() {
super.onResume();
Toast.makeText(getApplicationContext(), "onResume", Toast.LENGTH_SHORT).show();
buttonToggleDetect.setBackground(ui.uiToggle(getApplicationContext(), detectEnabled));
// ACTIVITY RECOGNITION BELOW
LocalBroadcastManager.getInstance(this).registerReceiver(mBroadcastReceiver, new IntentFilter(Constants.STRING_ACTION));
// ACTIVITY RECOGNITION ABOVE ^^
mTracker.setScreenName("Image~" + name);
mTracker.send(new HitBuilders.ScreenViewBuilder().build());
}
@Override
protected void onPause() {
Toast.makeText(getApplicationContext(),"onPause",Toast.LENGTH_SHORT).show();
LocalBroadcastManager.getInstance(this).unregisterReceiver(mBroadcastReceiver);
super.onPause();
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
public void onStart() {
super.onStart();
Toast.makeText(getApplicationContext(), "onStart", Toast.LENGTH_SHORT).show();
// ACTIVITY RECOGNITION BELOW
mGoogleApiClient.connect();
// ACTIVITY RECOGNITION ABOVE ^^
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
detectEnabled = preferences.getBoolean("mode", false);
buttonToggleDetect.setBackground(ui.uiToggle(getApplicationContext(), detectEnabled));
}
@Override
public void onStop() {
super.onStop();
Toast.makeText(getApplicationContext(),"onStop",Toast.LENGTH_SHORT).show();
// ACTIVITY RECOGNITION BELOW
if (mGoogleApiClient.isConnected()) {
mGoogleApiClient.disconnect();
}
// ACTIVITY RECOGNITION ABOVE ^^
}
public void onDestroy() {
super.onDestroy();
Toast.makeText(getApplicationContext(),"onDestroy",Toast.LENGTH_SHORT).show();
} //onDestroy End
无法弄清楚如何解决它。 任何帮助将不胜感激!谢谢。
【问题讨论】:
-
请发布您的代码
-
添加到那里的代码
标签: android android-activity android-lifecycle oncreate