kgnzpk
kgnzpk

Reputation: 128

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.

Upvotes: 2

Views: 2508

Answers (1)

Naveen Tamrakar
Naveen Tamrakar

Reputation: 3339

Pass an Instance of Context via Constructor

class YourClass {
    private Context context;

    public YourClass(Context context) {
        this.context=context;
    }    
}

Upvotes: 4

Related Questions