DEV Community

John Melody Me
John Melody Me

Posted on

Answer: Start a new Activity from non Activity class

For Easy Usage you can a method for this particular method:

public class Something
{
   public static void navigate(Context context,  Class<?> nameOfClass)
    {
        Intent i = new Intent(context, nameOfClass);
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(i);
    }
}

can be called in other class and method everytime by calling this:

Something.navigate(activityName.this, classYourWantTONavigateTo.class);

Top comments (0)