Reputation: 1955
I have a simple Android app with a single Activity that contains a TextView. I created a BroadcastReceiver whose purpose is to perform some numerical calculations, convert the result into a String, and then change the TextView's text value to that String. However, since the BroadcastReceiver is usually called when the App's Activity doesn't exist, I can't seem to find a way to access the Activity's TextView (I always get a NullPointerException).
I've read other articles here on StackOverflow that suggest implementing a Listener for my BroadcastReceiver with a callback method, but I'm honestly not sure how to implement this. I'm somewhat familiar with the concept of a callback method, I'm just not sure how to implement it in this context. Can anyone please suggest how I might accomplish this? Thank you!
Upvotes: 0
Views: 1094
Reputation: 11608
EDIT
Using an AsyncTask
would do to perform operations in background. Example one Example two
Note that you have to pass your TextView
to the AsyncTask
inside its constructor
Upvotes: 1