1
我是Android的新开发人员。我在分段和通知方面遇到困难。这里有一些我的代码。单击从片段到另一个片段的通知
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;
}
我想的是,测试片段将显示第一,有一个通知,但该代码的结果是NextFragment类是始终显示出来。请告诉我我错了哪里。我感谢任何帮助。非常感谢。
感谢你的答案,但为什么我需要一个报警?我只是想让测试片段类成为第一个实际显示的测试片段类在抽屉中。 – natsuVsnaruto
我认为问题出现在这一行: - – Nainal
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); – Nainal