Android intent bundle always null?

后端 未结 3 657
悲&欢浪女
悲&欢浪女 2020-12-21 18:28

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 b

相关标签:
3条回答
  • 2020-12-21 19:03

    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);
    
    0 讨论(0)
  • 2020-12-21 19:06

    Don't know why it would be returning null, but your code would not work even if the bundle was coming through correctly because you are doing string comparison with ==

    This line:

            if(well == standard) method();
    

    Should be

            if(well.equals(standard)) method();
    
    0 讨论(0)
  • 2020-12-21 19:22

    From the documentation:

    The keys must include a package prefix, for example the app com.android.contacts would use names like "com.android.contacts.ShowAll".

    so instead why don't you just use

    intent.putExtra("WELL", "yes");
    
    0 讨论(0)
提交回复
热议问题