Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am running the below code. There are two snippets. The first is how I am setting the bundle and the second how I am retrieving it. For some reason every time i check the bundle it returns as null.

Any advice on why this is or what I have done wrong would be greatly appreciated.

    Intent intent = new Intent(this, com.hom.app.Hom.class);
        Bundle b = new Bundle();
        b.putString("WELL", "yes");
        intent.putExtras(b);
    startActivity(intent);

Retrieving Bundle:

    String well ="";
    Bundle bun = getIntent().getExtras();
    String standard = "yes";
    if(bun != null){       
        Log.v("Bundle", "Contains data");
        well = bun.getString("WELL");
        if(well == null) well = "";
        if(well == standard) method();
    }   
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
649 views
Welcome To Ask or Share your Answers For Others

1 Answer

When you are creating your intent, just put the extras right in there. you are trying to access the wrong bundle in your code above. Something like this should work.

    Intent intent = new Intent(this, com.hom.app.Hom.class);
    intent.putExtras("WELL", "yes");
    startActivity(intent);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...