chkm8
chkm8

Reputation: 1302

Load the fragment when notification is click android

I'm having problem in my application. I have a notification that is being push in action bar. When you click the notification, you will be redirected to the specific activity that you set. In my scenario, once the notification is being clicked or touch, I should be redirected to the specific fragment of my current activity.(current activity is handling the fragments)

Now, this is were i stock,I made tried something like this but no luck. -when notification is clicked, it will launch another activity(NotificationControllerActivity) which when loaded, it will call the currect activity and display the fragment(a public method to load fragments).My error is, I cant cast NotificationControllerActivity into currentactivity.(i'm lookinf for solutions).

I would really appreciate your feedback.

thanks

Upvotes: 3

Views: 3596

Answers (1)

Kapil Vij
Kapil Vij

Reputation: 312

//Set pending intent for notification 

Intent intent = new Intent(this, RequiredActivity.class);
        intent.putExtra("key1", value);
        intent.putExtra("key2", value);

PendingIntent pIntent = PendingIntent.getActivity(this,0, intent, Intent.FLAG_ACTIVITY_NEW_TASK); 

// And in Required Activity override method onNewIntent(),and open up your required fragment.

Upvotes: 1

Related Questions