android - How to get the activity which called the BroadcastReceiver? -


i have broadcastreceiver checks networkchange, whether connected internet or not.

so in application when network disconnected or connected, want know activity has called broadcastreceiver, can go previous activity after showing alert informing network.

my code,

public class networkchangereceiver extends broadcastreceiver {  private android.widget.toast toast;  @override public void onreceive(final context context, final intent intent) {     try {         boolean isvisible = myapplication.isactivityvisible();         context appcontext = context.getapplicationcontext();         if (isvisible == true) {             if (checkinternet(context)) {                 /*intent = new intent(context, mainactivity.class);                 i.addflags(intent.flag_activity_new_task);                 context.startactivity(i);*/                   toast.maketext(context, "network available operations", toast.length_long).show();             } else {                 intent = new intent(context, nonetworkalert.class);                 i.addflags(intent.flag_activity_new_task);                 context.startactivity(i);                 toast.maketext(context, "network not available operations", toast.length_long).show();             }    .........   ...... 

here in above code, when internet reconnected, if (checkinternet(context))i want activity triggered this.

i assume current activity on top 1 triggers networkchangelistener. if can use below code snippet,

activitymanager = (activitymanager)context.getsystemservice(context.activity_service); componentname cn = am.getrunningtasks(1).get(0).topactivity; 

which give current activity on top.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -