Call an activity method from a BroadcastReceiver. Is it possible?

Try something like this In you activity code write BroadcastReceiver connectionReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { myActivityMethod();// Here you call method } }; registerReceiver(connectionReceiver, new IntentFilter("com.test. NET_CONNECTION")) And in your service write Intent intent = new Intent("com.test. NET_CONNECTION"); sendBroadcast(intent) If any confusion let me know i'll try to solve.

Try something like this.. In you activity code write BroadcastReceiver connectionReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { myActivityMethod();// Here you call method } }; registerReceiver(connectionReceiver, new IntentFilter("com.test. NET_CONNECTION")); And in your service write Intent intent = new Intent("com.test. NET_CONNECTION"); sendBroadcast(intent); If any confusion let me know i'll try to solve..

Even though I don't use a service (only an activity) I used the code in the activity and ommited the code for the service. It worked nicely. Thank you very much for your help!

This issue had been driving me crazy for a couple of days. – Jimix Feb 24 at 12:37.

I'm stuck developing an app because I need to call a method of my activity when a BroadcastReceiver is triggered. I want the BroadcastReceiver to detect when a network connection goes down and call a method of my activity which I've already written. I've been searching and I found that more people had asked this before but nobody got an answer about how to do it.

I think that maybe android's API doesn't allow it. If it's impossible to call a method of my activity from the BroadcastReceiver are there other ways to do this?

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions