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)

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay