-1

I have an activity in which i am getting some value in string and i want to send that data to another activity. The data that i want to send changes frequently after calling some method. So i want to send updated data into another activity. My data will be updated anytime no matter whether i am on that activity or not. My code

    if (event.equals("gameRequstinvitaion")) {
                        try {
                            socket.emit("gameRequstinvitaion", jsonObject);
                            gamerequest = jsonObject.toString();
                            Log.e("TAG", "gamereq" + gamerequest);
}
}

My gamerequest will be updated anytime so i want to send updated data to another activity. Is it possible?PleASE HELP ME OUT

Mehdi
  • 171
  • 1
  • 3
  • 14
  • No i already have activity started. I only want to send data to another activity that has already been started before.... – Mehdi Sep 29 '14 at 09:51
  • Please clarify your requirement. Is there some service running that keeps on updating data?? Or it is just one activity? – Pr38y Sep 29 '14 at 09:51
  • Its just an activity.......some method will call so it will update new data ,..... – Mehdi Sep 29 '14 at 09:52
  • If you want to send data to the previous activity then you can use putExtra and the finishing current activity previous activity will receive updated data. – Pr38y Sep 29 '14 at 09:54
  • can it be possibel with sharedpreference – Mehdi Sep 29 '14 at 09:58

3 Answers3

2

Use Handler to send data to another activity

  public static Handler handler;

handler=new Handler(new Handler.Callback() {

    @Override
    public boolean handleMessage(Message msg1) {

        //-- retreiving data
        String data=msg.obj.toString();
        return false;
    }
});

Now pass data from activity 1

 Message msg=new Message();
msg.obj="Test Message";//Pass any type of value
Activity2.handler.sendMessage(msg);

Cheers

0

I think what you are looking for is sending and receiving broadcast messages between activities. Refer:

How to send and receive broadcast message

Or This tutorial. http://hmkcode.com/android-sending-receiving-custom-broadcasts/

Community
  • 1
  • 1
A Nice Guy
  • 2,676
  • 4
  • 30
  • 54
0

use of interface...

when the upload is successfull , it will fire the interface method

in that defination of method in activity will navigate to activity to carry data with put extra.

deepak825
  • 432
  • 2
  • 8