java - Need context in non-activity -
i have mainactivity, class called failedpasswordhandler , camerahandler. failedpasswordhandler implements deviceadminreceiver. want create camerahandler object in failedpasswordhandler class, requires context argument. how context failedpasswordhandler class?
this have in mainactivity:
intent intent = new intent(devicepolicymanager.action_add_device_admin); componentname deviceadmin = new componentname(mainactivity.this, failedpasswordhandler.class); intent.putextra(devicepolicymanager.extra_device_admin, deviceadmin); startactivityforresult(intent, 1);
and want create camerahandler object this, in failedpasswordhandler class started intent above:
ch = new camerahandler(this); ch.initializecamera();
the 'this' argument being mainactivity.
i handle using custom application
class. example:
public class helper extends application { private context mcontext; public void oncreate() { super.oncreate(); mcontext = this; } public context getcontext() { return mcontext; } }
this way can context of application every time need it.
Comments
Post a Comment