Q: update textview from BroadcastReceiver running in the background initiated in manifest which starts when internet network is available I am using BroadcastReceiver to sync data and it should update textview if that activity is opened.I have created a class which determines if the activity is opened or closed.But,it still does not update the textview .I am passing the context.The code executes but does not update the textview .How should I update UI in BroadcastReceiver? Also,Its not within Activity class.SO I tried the code below to access the layout and findviewbyid for that textview.How can I settext? I really appreciate any help.
LayoutInflater inf = LayoutInflater.from(context);
View myView = inf.inflate(R.layout.layout1, null);

text=(TextView)myView.findViewById(R.id.textView1);
text.setText(date.toString());


A: Try running your code on the UI thread
someActivity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
           //Your code to run in GUI thread here
        }
});

