0

I'm having a problems.

In a class "A" I have the code:

Intent cInt = new Intent(Add_Product_Page.this, CategoryListActivity.class);
Bundle extra = new Bundle();
extra.putBoolean("for_result", true);
startActivityForResult(cInt, GET_CATEGORY, extra);

This code is from another class that starts the activity

Bundle extra = getIntent().getExtras();

        if (extra != null) {

            isforResult = cInt.getBooleanExtra("for_result", true);
            setIsforResult(isforResult);

        } else {
            setIsforResult(false);
        }

        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setTitle("Category");

    }

I debugged Class A and I got the value of extra as true but when I am debugged another class I am getting NULL in the extra

Can anybody help me.

Thanks in advance

Priyanka
  • 47
  • 7

4 Answers4

0

try like this

 isforResult = extra.getBoolean("for_result", true);

and remove this Intent extra = getIntent(); line it's a duplicate instance.

RajaReddy PolamReddy
  • 22,428
  • 19
  • 115
  • 166
0

Try this

      Bundle extra = getIntent().getExtras();

        if (extra != null) {

            isforResult = extra.getBoolean("for_result", true);
            setIsforResult(isforResult);

        } else {
            setIsforResult(false);
        }

        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setTitle("Category");

    }
Muthu
  • 1,022
  • 1
  • 7
  • 17
0

Use in Activity A

Intent in = new Intent(this, RegistrationActivity.class); in.putExtra("yourKey", yourValue); startActivityForResult(in, REQUEST_CODE);

and in Activity B

Bundle b = getIntent().getExtras();
    if (b != null) {
        boolean value = getIntent().getBooleanExtra("yourKey", true);

    }
Kalu Khan Luhar
  • 1,044
  • 1
  • 22
  • 35
0

startActivityForResult()'s 3rd argument(Bundle option) is not "extra" bundles.
See Context#startActivity(Intent, Bundle) for detail. That is launch configuration.

use Intent#putExtra(String, boolean) for boolean extras.

Intent intent = new Intent(Add_Product_Page.this, CategoryListActivity.class);
intent.putExtra("for_result", true);
startActivityForResult(intent, GET_CATEGORY);

then

boolean b = getIntent().getBooleanExtra("for_result", false);

This is equivalant to

boolean b = getIntent().getExtras().getBoolean("for_result");

Also you can check intent has extra parameter or not:

intent.hasExtra("for_result");
ytRino
  • 1,450
  • 15
  • 28