Skip to content Skip to sidebar Skip to footer

Start A New Intent By Setclassname With Same Package In Android

I have to start a activity class , i know how to start an activity but the problem is that my class name is dynamic. I mean we have 5 activity named 1. Events 2. Notification 3. C

Solution 1:

I think you are just missing a . character in your specified string for the Intent in the following line:

intent = newIntent().setClassName("com.mcm.menuandnotification",
        "com.mcm.menuandnotification" + NameOfClass);

Change it to:

intent = newIntent().setClassName("com.mcm.menuandnotification",
        "com.mcm.menuandnotification." + NameOfClass);

EDIT:

If that didn't work, how about trying the following:

Class<?> clazz = Class.forName("com.mcm.menuandnotification." + NameOfClass); 
intent.setClass(this, clazz);

Solution 2:

Have a look at this answer.

Intentintent=newIntent(Intent.ACTION_MAIN).addCategory(
intent.CATEGORY_LAUNCHER).setClassName("com.mcm.menuandnotification",
        "com.mcm.menuandnotification." + NameOfClass).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.addFlags(Intent.FLAG_FROM_BACKGROUND).setComponent(newComponentName("com.mcm.menuandnotification",
        "com.mcm.menuandnotification." + NameOfClass));

Cannot start new Intent by setClassName with different package in Android

Post a Comment for "Start A New Intent By Setclassname With Same Package In Android"