清除缓存后重启 android 应用
Restart android app after cache clear
安装 android 应用程序更新后,我正在使用 clearApplicationUserData()
清除应用程序缓存。一旦上述方法运行,应用程序立即关闭。关闭应用程序本身后重新启动应用程序有什么建议吗?
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();
}
好吧,看看这个 solution 它似乎有正确的方法来做到这一点。通过将以下代码添加到 startActivity
intent = PendingIntent.getActivity(YourApplication.getInstance().getBaseContext(), 0,
new Intent(getIntent()), getIntent().getFlags());
- 您可以创建 local broadcast receiver and a
BroadcastReceiver
that would listen to it。
- 在
onDestroy
或 onStop
内调用您的 MainActivity
。
试试这个:
@Override
public void onStop(){
recreate();
}
安装 android 应用程序更新后,我正在使用 clearApplicationUserData()
清除应用程序缓存。一旦上述方法运行,应用程序立即关闭。关闭应用程序本身后重新启动应用程序有什么建议吗?
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();
}
好吧,看看这个 solution 它似乎有正确的方法来做到这一点。通过将以下代码添加到 startActivity
intent = PendingIntent.getActivity(YourApplication.getInstance().getBaseContext(), 0,
new Intent(getIntent()), getIntent().getFlags());
- 您可以创建 local broadcast receiver and a
BroadcastReceiver
that would listen to it。 - 在
onDestroy
或onStop
内调用您的MainActivity
。
试试这个:
@Override
public void onStop(){
recreate();
}