2017-06-26 12 views
-1

JSONObjectデータには、受け取ったファイヤーベースの通知メッセージがあります。通知はトレイに積み重ねられます。メッセージの最初の値は "Hi"で、メッセージの2番目の値は "Hello"です。私は両方の値を次の活動に送る必要があります。しかし、唯一の「こんにちは」(第二の値)は、次のアクティビティに印刷されAndroidのインテントを使用して次のアクティビティにデータを渡す

private void sendPushNotification(JSONObject json) { 
    //optionally we can display the json into log 
    Log.e(TAG, "Notification JSON " + json.toString()); 
    try { 
     //getting the json data 
     JSONObject data = json.getJSONObject("data"); 

     //parsing json data 
     String title = data.getString("title"); 
     String message = data.getString("message"); 
     String imageUrl = data.getString("image"); 

     //creating MyNotificationManager object 
     MyNotificationManager mNotificationManager = new MyNotificationManager(getApplicationContext()); 


     Intent intent = new Intent(getApplicationContext(), HomeActivity.class); 
     intent.putExtra("time",message); 
     //if there is no image 
     if(imageUrl.equals("null")){ 
      //displaying small notification 
      mNotificationManager.showSmallNotification(title, message, intent); 
     }else{ 
      //if there is an image 
      //displaying a big notification 
      mNotificationManager.showBigNotification(title, message, imageUrl, intent); 
     } 
    } catch (JSONException e) { 
     Log.e(TAG, "Json Exception: " + e.getMessage()); 
    } catch (Exception e) { 
     Log.e(TAG, "Exception: " + e.getMessage()); 
    } 

HomeActivity.java

Intent i=getIntent(); 
    String times = i.getStringExtra("time"); 
+0

uは完全なコードを共有することができ、あなたが値を設定しているか、そしてどのようにあなたはそれを取得していますか? – Shekhar

+0

両方の文字列に同じキーを使用するので、秒だけが保存されます。 –

+0

私が与えた答えをお試しください。 – Shekhar

答えて

0
// In Current Activity 
Bundle bundle = new Bundle(); 
bundle.putString("key_hi", "Hi"); 
bundle.putString("key_hello", "Hello"); 

Intent intent = new Intent(this, NextActivity.class); 
intent.putExtras(bundle); 
startActivity(intent); 

// In HomeActivity.java 
Bundle bundle = getIntent().getExtras(); 
String strHi = bundle.getString("key_hi"); 
String strHello = bundle.getString("key_hello"); 
+0

@Shekar実際にJsonメッセージには最後に受信した通知メッセージのみが含まれており、次のアクティビティ – Sumi

+0

に渡されていますので、以前の通知も保存しますか? – Shekhar

+0

@Shekar通知バーに複数の受信通知からの通知をタップするだけで、そのメッセージだけが次の操作に渡されます – Sumi

関連する問題