I'm a new developer of android. I'm having difficulty in fragments and notification side. Here some of my codes.
test.java
public class test extends Fragment {
\\some of codes here up.
@Override
public View onCreateView(LayoutInflater, ViewGroup container, Bundle savedIntancesState) {
View view = inflater.inflate(R.layout.test_fragment, container, false);
Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
PendingIntent resultPendingIntent = PendingIntent.getActivity(getActivity(), fragmentManager.beginTransaction().replace(R.id.flContent, NextFragment.newInstance("message", R.layout.content_row)).commit(), getActivity().getIntent(), PendingIntent.FLAG_UPDATE_CURRENT);
Notification notification = new NotificationCompat.Builder(getActivity())
.setContentTitle(title)
.setContentText(message)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentIntent(resultPendingIntent)
.setSound(soundUri)
.addAction(R.mipmap.ic_launcher, "Call",resultPendingIntent).build();
NotificationManager notificationManager = (NotificationManager) getActivity().getSystemService(NOTIFICATION_SERVICE);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0,notification);
return view;
}
I want that the test Fragment will be shown first and have a notification, but the result of that code is the NextFragment class is always show up. please tell me where i go wrong. I appreciate any help. Thank you so much.