Android pin activity on boot

后端 未结 3 1997
一整个雨季
一整个雨季 2021-02-14 17:05

I\'ve got an app that registers itself as the default launcher and pins itself automatically when started.

This all works fine when installing the app. It pins itself a

3条回答
  •  太阳男子
    2021-02-14 17:21

    Sorry for late answering, but...
    Anyone has this problem can do this tricky work in first (LAUNCHER/HOME) activity (e.g. MainActivity):

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
        if (mSharedPreferences.getBoolean(KEY_PREF_RECREATED, false)) {
            mSharedPreferences.edit().putBoolean(KEY_PREF_RECREATED, false).apply();
    
            // start LOCK TASK here
        } else {
            mSharedPreferences.edit().putBoolean(KEY_PREF_RECREATED, true).apply();
    
            finish(); // close the app
            startActivity(new Intent(this, MainActivity.class)); // reopen the app
            return;
        }
    
        setContentView(R.layout.activity_main);
    
        // other codes
    }
    

提交回复
热议问题