清除数据并重新启动应用程序的Andr​​oid [英] Clear data and restart app android

查看:114
本文介绍了清除数据并重新启动应用程序的Andr​​oid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要清除数据,并在我的应用程序重新启动应用程序。为此,我已经使用下面的code。然而,它似乎并没有工作。请帮助我!

I want to clear data and restart app in my app. For this I've used the code below. However, it doesn't seem to work. Please help me out !

deleteDatabase(Universal.database_name);
Intent i = getBaseContext().getPackageManager().getLaunchIntentForPackage( getBaseContext().getPackageName() );
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK );
startActivity(i);

编辑:我看不出有什么效果和应用程序简单地用数据完全保留重新启动

I see no effect and the app simply restarts with data absolutely retained !

推荐答案

**此活动说明不了什么;相反,它重新启动了Android程序* /

** This activity shows nothing; instead, it restarts the android process */

public class AppRestartActivity extends Activity {
    // Do not forget to add it to AndroidManifest.xml
    // <activity android:name="your.package.name.AppRestartActivity"/>
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        System.exit(0);
    }
    public static void doRestart(Activity anyActivity) {
        anyActivity.startActivity(new Intent(anyActivity.getApplicationContext(), MagicAppRestart.class));
    }
}

这篇关于清除数据并重新启动应用程序的Andr​​oid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆