2016-04-01 22 views
0

のパラメータとして活動を渡す:ユーザーが通知をクリックすることができるようにあなたが見ることができるように私のように定義された通知持っ通知

private void sendNotification(String msg, Activity onClickActivity) { 

     mNotificationManager = (NotificationManager) this 
       .getSystemService(Context.NOTIFICATION_SERVICE); 

     // Send to the login activity, since if already a member and logged in, should be able to start that activity 

     PendingIntent contentIntent = PendingIntent.getActivity(this, 0, 
       new Intent(this, onClickActivity), 0); 

     NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
       this).setSmallIcon(R.drawable.gcm_cloud) 
       .setContentTitle("Hello") 
       .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)) 
       .setContentText(msg); 

     mBuilder.setContentIntent(contentIntent); 
     mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); 

    } 

を、私は、PendingIntentへの動的参照を許可することができるようしたいと続いてActivity onClickActivityという異なる活動にアクセスします。現時点では、エラーはコンストラクタを解決できないことに注意しています。

これを動作させるにはどうすればよいですか?

答えて

1

Intent constructorはであり、instanceではありません。メソッドの署名を

private void sendNotification(String msg, Class<? extends Activity> onClickActivity) { 
に変更するだけです
関連する問題