there is no way to do it directly the way you want. To set a launcher activity, you have to edit the manifest, and you can't do it actually.
But what you can do is to declare some LauncherActivity
in a manifest using this intent filter:
<activity
android:name="com.sample.test.LauncherActivity"
android:label="@string/title_activity_main">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
And inside of it's onCreate() method read previously saved activity name, you really need to start by clicking on app icon from SharedPreferences
, and start it. Like this:
public class LauncherActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String activityToLaunch = getSharedPreferences("LauncherActivity", MODE_PRIVATE).getString("LauncherActivity", "Some default Activity");
Intent intent;
switch (activityToLaunch) {
case "SomeActivity1":
intent = new Intent(this, SomeActivity1.class);
break;
case "SomeActivity2":
intent = new Intent(this, SomeActivity2.class);
break;
case "SomeActivity3":
intent = new Intent(this, SomeActivity3.class);
break;
default:
intent = new Intent(this, SomeDefaultActivity.class);
break;
}
startActivity(intent);
finish();
}
}