how to detect if user clicked done or open after application in android has been installed programmatically

后端 未结 2 901
终归单人心
终归单人心 2021-01-16 01:02

I\'m having trouble detecting if the user clicked the dialog, that usually pops up after the android application has been installed. So that I can proceed to the next instal

2条回答
  •  庸人自扰
    2021-01-16 01:27

    You can't detect that.

    If you are wanting to do some operation on the first run of the application then just store a "first run" flag within your user preferences and default it to true.

    You can then check this on start of your app and perform any necessary operations.

    Some example code for this;

    private boolean prefFirstRun;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        settings = PreferenceManager.getDefaultSharedPreferences(this);
    
        prefFirstRun= settings.getBoolean("FirstRun", true);
    }
    
    @Override
    protected void onStart() {
        super.onStart();
    
        if (prefFirstRun) {
            prefFirstRun = false;
            // Do your initial operations here
        }
    }
    
    @Override
    protected void onStop() {
        super.onStop();
    
        SharedPreferences settings = PreferenceManager
                .getDefaultSharedPreferences(this);
        SharedPreferences.Editor editor = settings.edit();
        editor.putBoolean("FirstRun", false);
        editor.commit();
    
    }
    

提交回复
热议问题