[英]Why Activity onPause calling only if i press Back or Home button?
我需要保存關閉應用程序時的播放時間,但如果我單擊任務管理器並關閉應用程序或切換到其他應用程序並關閉它,則我的應用程序確實保存了任何內容。
onStop的代碼
@Override
protected void onStop() {
super.onStop();
Log.d("", "MainActivity: onStop()");
SearchFragment.sPref = MainActivity.this.getPreferences(Context.MODE_PRIVATE);
SharedPreferences.Editor ed = SearchFragment.sPref.edit();
ed.putLong("SAVED_TIME", SearchFragment.mediaPlayer.getCurrentPosition());
ed.commit();
}
如果調用了“ onPause”並且“活動”仍處於“后台”,則將不再調用它。 活動的生命周期: http : //developer.android.com/images/activity_lifecycle.png
也許您需要在“ onPause”中打印日志並檢查何時調用它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.