android - How to get the foregrund activity instance? -
i try foreground activity long time, , didn't managed until now.
i don't know if possible, dont intersted in app activity only.
there no data transfer between service , activity want get.
i saw lot of questions of kind got nothing suitable needs.
i need instance, not componentname, not decription of current foreground activity.
i've tried through activitythread, activitymanager, activitymanagerservice (even though couldnt instance too), , on.
field activitiesfield = activitythreadclass.getdeclaredfield("mactivities");// won't activitymanager.getrunningtasks(rnd);// won't either if there refelection way, listener or that, not static field.
without knowing why want instance of activity, or other background info. i'd suggest following.
if you're inside fragment, can getactivity() - give reference activity, , can cast own activity.
otherwise, might want consider having broadcastreceiver, can start activity you.
you shouldn't accessing activity directly. if have methods/logic need access, might consider refactoring them helper class.
edit:
"your application runs in secure sandbox environment, other processes on system cannot access code or private data." take official android docs
Comments
Post a Comment