Mak
Mak

Reputation: 1063

Android How to get First Activity's Handler data into third activity?


I have three activities A,B,and C.


I go from Activity A -> Activity B -> Activity C Now currently Activity C is displaying and Activity A is bottom on Activity Stack then I provide some inputs to Activity C through which the another thread send some data to Handler of Activity A.


Now I want to receive that data on my Activity C.


Can any possible solution ? Should I use intent and if yes then can u give me appropriate guidance ?

Thanks in Advance.

Upvotes: 0

Views: 749

Answers (3)

Semere Taézaz Sium
Semere Taézaz Sium

Reputation: 4036

It sounds like you are trying to pass massages from one to activity to the other. You can use a singleton class to do that. Here is a skeleton you can use

// Singleton Class for message passing
public class Messenger {

    private static Messenger instance = new Messenger();

    public static Messenger get() {
        return instance;
    }

    private String  theMessage_;

    // Default Constructor
    private Messenger() {
    }


     // Setter to set the message you want to pass
    public void setMessageToBePassed(String myMessage){
        theMessage_ = myMessage;
    }


    // Getter to get the message that is passed to you
    public String  getMessage(){
        return theMessage_;
    }

}

Upvotes: 0

Mike dg
Mike dg

Reputation: 4658

Pass data through intents as extras. USe .putExtra and just pass from B to C.

Upvotes: 1

Vineet Shukla
Vineet Shukla

Reputation: 24031

If data is for decision purpose only then you can use static or SharedPreference and use handler to notify that the data has come or changed.

Upvotes: 1

Related Questions