1

i have a problem with updating my textview. i am making a c2dm app. the messages i send are being recieved by the device (as i have put the message to display in the notifcation bar. also i have many logs that state a message has been received). however once i click on a message within the notification area to open up my view it only shows my 1 message. e.g i send a message, then i want to send another message only the first message shows.

i have found out i may need an onNewIntent however i'm not sure if i have gone around it in the correct manner.

 public class MessageReceivedActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_result);
        Bundle extras = getIntent().getExtras();            

        if (extras != null) {
            String message = extras.getString("payload");
            if (message != null && message.length() > 0) {
                TextView view = (TextView) findViewById(R.id.result);
                view.setText(message);
            }
        }

        super.onCreate(savedInstanceState);     
    }
     @Override
     protected void onNewIntent(Intent intent) {             

            setContentView(R.layout.activity_result);
            Bundle extras = getIntent().getExtras();                

            if (extras != null) {
                String message = extras.getString("payload");
                if (message != null && message.length() > 0) {
                    TextView view = (TextView) findViewById(R.id.result);
                     setIntent(intent);
                    view.setText(message);    
                }
            }               
//         setIntent(intent);          
     }
}

my layout is activity_result which contains only 1 textview my text view is called result and payload is the message i send from my server

any help would be appreciated

Yugandhar Babu
  • 10,311
  • 9
  • 42
  • 67
Tuffy G
  • 1,521
  • 8
  • 31
  • 42

5 Answers5

0

Update Textview from function Android how to change text in Android TextView

Hope they can help. Is there a reason for not using edittext for these kind of situations? I'm new in this.

Community
  • 1
  • 1
cagla
  • 538
  • 4
  • 7
0

I think you need to lookout at your notification ids. You send messages, but all of them have the same notification id. You should somehow increment the notification id.

Dany's
  • 943
  • 1
  • 7
  • 17
  • its not that. it only displays messages that have been received the first time the app has been opened. i can see the message in the notification however doesnt update my textview – Tuffy G Mar 22 '12 at 10:08
0

in onNewIntent() method, you should use setIntent(intent) before Bundle extras = getIntent().getExtras(); or the extras is null

and setContentView(R.layout.activity_result) is not necessary in onNewIntent()

mcxiaoke
  • 188
  • 2
  • 8
  • thats a negative. not working. i tried: protected void onNewIntent(Intent intent) { // setContentView(R.layout.activity_result); setIntent(intent); Bundle extras = getIntent().getExtras(); if (extras != null) { String message = extras.getString("payload"); if (message != null && message.length() > 0) { TextView view = (TextView) findViewById(R.id.result); view.setText(message); } } – Tuffy G Mar 22 '12 at 10:21
0

in Acitity A:

Intent mIntent = new Intent();  
        mIntent.setClass(mContext, MessageReceivedActivity.class);  

        mIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);  

        mIntent.putExtra("payload", "fdfsfnj");  
        mContext.startActivity(mIntent);  

in Acitity MessageReceivedActivity :

    @Override  
        protected void onNewIntent(Intent intent)  
        {  

            String message  = intent.getData();  
            //Or you can use
            String message  = getIntent().getStringExtra("payload", ""); 
super.onNewIntent(intent);  
        }  
ρяσѕρєя K
  • 132,198
  • 53
  • 198
  • 213
0

for all those with this problem. i had a look on another stack overflow question heres the answer. in message receiver inside createNotification add this

    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,intent, 
            PendingIntent.FLAG_CANCEL_CURRENT);

dont forget the flag at the end that cancels the current view

Tuffy G
  • 1,521
  • 8
  • 31
  • 42