I want to update my text view on the receivers side as soon as I receive the message. I have the following code which creates the instance of main activity and uses it in the Broadcast receiver to update UI. But the text view isn't getting updated??
public class Mainactivity extends activity{
private static MainActivity ins;
public static MainActivity getInst()
{
return ins;
}
protected void onCreate(Bundle savedInstanceState) {
ins=this;}
public void updateUI(final String s)
{
MainActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
TextView textView=(TextView) findViewById(R.id.textView);
textView.setText(s);
}
});
}
In the smsreceiver class
public class smsreceiver extends BroadcastReceiver
{
try{
if (MainActivity.getInst()!=null)
MainActivity.getInst().updateUI(str);
}
catch(Exception e){
e.printStackTrace();
}
}
Please help me out!!