Search code examples
androidandroid-intentintentfilter

How to change main activity in Android programmatically


Is it possible to create two entry points to an application in Android, I mean can I switch the main activity programmatically?


Solution

  • check this one below

    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    intent.setComponent(new ComponentName(packageName,mainActivity));
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    ctx.startActivity(intent);