1
私はアンドロイドの新しい開発者です。私はフラグメントや通知側に問題があります。ここで私のコードのいくつか。フラグメントから別のフラグメントへの通知をクリック
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