java - Calling MainApplication methods from BroadcastReceiver -


i have android application activity, service , broadcast receiver. service call broadcast intent works. broadcast receiver receives intent correctly.

but how can access methods of class mainapplication class mybroadcastreceiver ?

((mainapplication)getapplication()).mymethod(); gives error-message "cannot resolve method"

//call service-class private void sendbroadcast() {     log.d(tag, "sending broadcast intent");     intent intent = new intent();     intent.setaction("com.package.name.mybroadcastreceiver");     intent.addflags(intent.flag_include_stopped_packages);     sendbroadcast(intent); }   //receiver class public class mybroadcastreceiver extends broadcastreceiver {     @override     public void onreceive(context context, intent intent) {         //doesn't work - "cannot resolve method"         ((mainapplication)getapplication()).mymethod();         //doesn't work either         ((mainapplication)context.getapplication()).mymethod();         toast.maketext(context, "intent detected.", toast.length_long).show();     } }    //main application class public class mainapplication extends application{      public void mymethod(){      }  } 

best regards

cast context activity:

//receiver class public class mybroadcastreceiver extends broadcastreceiver {     @override     public void onreceive(context context, intent intent) {         activity activity = (activity) context;         ((mainapplication)activity.getapplication()).mymethod();         toast.maketext(context, "intent detected.", toast.length_long).show();     } } 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -