Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android getApplicationContext() outside Activity and Application

How I can get application context outside activity and without extending application class.

class A{
public static B b = new B(App context here);
}

Objetc b must be as a field

like image 444
Denis Makovsky Avatar asked Dec 15 '25 00:12

Denis Makovsky


1 Answers

No you can't get context without extending Application or Activity by the given example. All that you can do is to have a static method in a class (extends Application) that would return context and then pass that method as a parameter to your B().

BTW, I did not get your intention of doing this. Can you detail out what exactly you wants to do.

Thank you

like image 50
Aziz Avatar answered Dec 16 '25 14:12

Aziz



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!