-1

i have a app with a listview and an adapter (ArrayAdapter).

Now i have an implementation of GCM with a backend, then when i receive a GCM Message, from the IntentService i need to do a

listViewActivityContext.getList().getAdapter().notifyDataSetChanged();

I think i need the activity context in the IntentService but i dont know how can i get it and check if its the context for the Activity that contains the ListView.

Anyone has an example?

Thanks.

colymore
  • 11,776
  • 13
  • 48
  • 90

2 Answers2

0

Register BroadcastReceiver in your Activity. When you receive push message from GCM, send message to registered BroadcastReceiver with data received from server, and update your ListView in BroadcastReceiver onReceive method.

Veaceslav Gaidarji
  • 4,261
  • 3
  • 38
  • 61
0

Basically this is the idea:

Use LocalBroadcastManager, register a listener in your Activity in onCreate() and send a signal from your Service.

Here is a good example:

how to use LocalBroadcastManager?

But replace the SenderActivity with your Service.

Community
  • 1
  • 1
brummfondel
  • 1,202
  • 1
  • 8
  • 11