Alright, i have read many different views on how to do this with no success. Maybe i am missing something or not doing something right, so any help i appreciate…
So, i have 2 Classes. Lets say Class A is an activity and has a public method called classAmethod();
Now, Class B actually extends a BroadcastReceiver. So in Class B i need to start classAmethod();
—
So far when i try this, it will want to make it static. But i cant do that. I have tried some other methods that dont make it static but for some reason it automatically wants it to be static and if something isn’t it will FC once the method is called.
There are a number of ways you can do this so I’ll just outline 2 ways I would do this.
Option 1. use a listener
create an interface
in the broadcast receiver create a static reference and setter
then implement the listener in the Activity
Option 2. use an intent
In the broadcast receiver
The flag
FLAG_ACTIVITY_SINGLE_TOPwill start the activity if its not started or if it is running it will be caught inonNewIntent()so you will need to put some code in both theonCreate()andonNewIntent()to extract the bundle and check for the action.Option 1 is really only useful for when the broadcast receiver is only going to be receiving when the activity is at the forefront. Option 2 is more versatile and can be used even when the app is not running (eg the broadcast receiver is run in a service started on boot) so that the activity will be started and the action performed no matter the state of the activity.