2016-12-14 16 views
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クラスです。どこが間違っているのか教えてください。私はどんな助けにも感謝します。どうもありがとうございます。

答えて

0

BroadcastReceiverを拡張するアラームを設定する別のクラスを作成し、それをあなたのFragmentから呼び出します。

Alarm Manager Example

EDIT: - - :リンク参照してください

をテストフラグメントレイアウトを膨らま: -

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
     View view = inflater.inflate(R.layout.test_fragment, container, false); 
     //your code for notification 
     return view; 
    } 
+0

は答えてくれてありがとう、しかし、なぜ私はアラームが必要でしょうか?私はちょうどテストフラグメントクラスが実際にテストフラグメントクラスが引き出しにある最初に表示されることを望みます。 – natsuVsnaruto

+0

私は問題がこの行であると思います: - – Nainal

+0

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

関連する問題