活动结束后一个新的安装只启动一次? [英] Activity that is only launched once after a new install?

查看:138
本文介绍了活动结束后一个新的安装只启动一次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我的应用程序有一个活动,展示说明如何使用的应用程序。然而,这个指令的屏幕只能使用一次后的表现安装,你怎么做到这一点?

I want my app to have an activity that shows instruction on how to use the app. However, this "instruction" screen shall only be showed once after an install, how do you do this?

推荐答案

您可以测试阉一个特殊的标志(姑且称之为 firstRun )的应用程序中的<$设置C $ C>共享preferences 。如果不是,这是第一次运行,因此表现出你的活动/弹出/不管的说明,然后在preference设置 firstRun

You can test wether a special flag (let's call it firstRun) is set in your application SharedPreferences. If not, it's the first run, so show your activity/popup/whatever with the instructions and then set the firstRun in the preference.

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    SharedPreferences settings = getSharedPreferences("prefs", 0);
    boolean firstRun = settings.getBoolean("firstRun", true);
    if ( firstRun )
    {
        // here run your first-time instructions, for example :
        startActivityForResult(
             new Intent(context, InstructionsActivity.class),
             INSTRUCTIONS_CODE);

    }
 }



// when your InstructionsActivity ends, do not forget to set the firstRun boolean
 protected void onActivityResult(int requestCode, int resultCode,
         Intent data) {
     if (requestCode == INSTRUCTIONS_CODE) {
         SharedPreferences settings = getSharedPreferences("prefs", 0);
         SharedPreferences.Editor editor = settings.edit();
         editor.putBoolean("firstRun", false);
         editor.commit();
     }
 }

这篇关于活动结束后一个新的安装只启动一次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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