Android intent package always null?

I am running the code below. There are two fragments. First, how do I install a package, and second, how do I extract it. For some reason, every time I check the package, it returns as null.

Any advice on why this is or what I did wrong will 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);

Extract Package:

    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();
    }   
+1
source share
3 answers

When you create your intention, just put extra features right there. You are trying to access the wrong set 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);
+3
source

I donโ€™t know why it will return null, but your code will not work even if the package passed correctly, because you are comparing strings with ==

This line:

        if(well == standard) method();

        if(well.equals(standard)) method();
+1

From the documentation :

The keys must contain the package prefix, for example, the com.android.contacts application will use names like "com.android.contacts.ShowAll".

so instead you just don't use

intent.putExtra("WELL", "yes");
+1
source

All Articles