Issue
I am writing a service that updates the textview in an AppWidget. It is about reading an RSS and displaying the text. So I need to set the text as "No Internet available" if the internet is not active on the device. So on the Service's onStart()
method I put
ConnectivityManager cm =
(ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
if(!netInfo)
{
try-catch block to fetch XML using XMLPULLPARSER and set the textview
}
else
set the textview using remoteview that there is no internet
But this is not working. The service is killed by background ANR. How do I check the network status?
Solution
Although Service
is designed for performing operations in the background, it still runs in the ui thread by default. If you want to do long running operations in the service you have to create a worker thread. Or you can use an IntentService
that creates it for you.
Answered By - Vladimir Mironov
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.