As I said in the heading, this is my problem. Why can't I access the context in my class? Is there any way I could get the instance of the context in this class?
[Service(Exported = false), IntentFilter(new[] { "com.google.android.c2dm.intent.RECEIVE" })]
class MyGcmListenerService : GcmListenerService
{
public override void OnMessageReceived(string from, Bundle data)
{
string msg = data.GetString("message");
// the app breaks here
ShowPopup(msg);
Log.Info("GcmLstnrService", "From: " + from);
Log.Info("GcmLstnrService", "Msg: " + msg);
}
private void ShowPopup(string message)
{
// the app breaks here
AlertDialog.Builder builder = new AlertDialog.Builder(Application.Context);
AlertDialog dialog = builder.Create();
dialog.SetTitle("Push message");
dialog.SetMessage(message);
dialog.SetButton("OK", (sender, e) => { });
dialog.Show();
}
}
See Question&Answers more detail:os