kgnzpk kgnzpk - 1 year ago 493
Java Question

Android get context from non Activity Class

I m creating an open source library for android in this library I should call a method on application start. After this method call I need to get context. Is there a way to get current context or activity from a static class without pass Context parameter to method. Is android send an intent when an activity start.

Answer Source

Pass an Instance of Context via Constructor

class YourClass {
    private Context context;

    public YourClass(Context context) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download