开发者

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.


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.


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


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_;
    }

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜