Reputation: 21
I have a class named 'GeofenceIntentService
' to receive Push Notification and I want to call fragment from that class, the class is extends IntentService
class.
Thanks in advance.
Upvotes: 0
Views: 251
Reputation: 116
If you need to open a screen, you should open an Activity which contains your Fragment, but not a Fragment instead.
For example:
Intent i = new Intent();
i.setClass(GeofenceIntentService.this, HostActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
If you need to communicate between Service and Fragment, look at Bound Service .
If you need to send a message to Fragment from the Service, use BroadcastReceiver
Upvotes: 1
Reputation: 1
I solved the problem. if we are using this in Fragment
its not find Activity
context.
We are using MyFragment.this.getActivity()
Intent intent = new Intent(MyFragment.this.getActivity(),MyService.class);
intent.putExtra("path",uri);
MyFragment.this.getActivity().startService(intent);
Upvotes: 0