I'm writing a GCM application. I'm unable to set a received message to a text view.
Check the below code:
public class GcmMessageHandler extends IntentService {
String mes;
private Handler handler;
public GcmMessageHandler() {
super("GcmMessageHandler");
}
@Override
public void onCreate() {
super.onCreate();
handler = new Handler();
}
@Override
public void onHandleIntent(Intent intent) {
Bundle extras = intent.getExtras();
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
String messageType = gcm.getMessageType(intent);
mes = extras.getString("title");
showMsg();
Log.i("GCM", "Received : (" +messageType+") "+extras.getString("title"));
GcmBroadcastReceiver.completeWakefulIntent(intent);
}
public void showMsg(){
handler.post(new Runnable() {
public void run() {
TextView textview = (TextView)findViewById(R.id.getMsg);
textview.setText(mes );
}
});
}
}
(Error msg : The method findViewById(int) is undefined for the type new Runnable(){})