Restart android app after cache clear

淺唱寂寞╮ 提交于 2019-12-11 06:47:06

问题


I am using clearApplicationUserData() for clear the app cache after install an update of the android application. Once above method runs, app close immediately. Any suggestion to restart the app after close the app itself?

if (Build.VERSION_CODES.KITKAT <= Build.VERSION.SDK_INT) {
    ((ActivityManager)SplashScreenActivity.this.getSystemService(ACTIVITY_SERVICE))
            .clearApplicationUserData(); 
    Toast.makeText(getApplicationContext(), "Cache cleared", Toast.LENGTH_LONG).show();
}

回答1:


  1. you can create a local broadcast receiver and a BroadcastReceiver that would listen to it.
  2. Inside onDestroy or onStop call your MainActivity.



回答2:


Alright looking at this solution it seem to have proper get way to do it. Is by adding below code to the startActivity

intent = PendingIntent.getActivity(YourApplication.getInstance().getBaseContext(), 0,
            new Intent(getIntent()), getIntent().getFlags());



回答3:


try this:

@Override
public void onStop(){

   recreate();

}


来源:https://stackoverflow.com/questions/38910401/restart-android-app-after-cache-clear

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!