Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is that possible to call for startActivity() from a static method?

Tags:

android

I need to call for a startActivity() from one of my static method, is that possible somehow?

like image 400
Eugene Avatar asked Dec 01 '25 15:12

Eugene


1 Answers

You'll need a context to be able to do that. Can you pass in a context into your static method as an argument?

public static void doSomething(Context ctx) {
    // do some stuff here
    ctx.startActivity(new Intent(ctx, OtherActivity.class));
}
like image 153
manavo Avatar answered Dec 03 '25 05:12

manavo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!