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
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
}