0

I am developing an app. And min SDK is 14. And now i am going to open new Activity from Fragment, when user clicks button on the fragment.

//code that open new activity

newFavoriteFAB.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Intent mIntent = new Intent(getActivity(), CategoriesActivity.class);
            Bundle mBundle = new Bundle();
            mBundle.putInt(BundleConstants.OPERATION_TYPE, OperationTypes.ADD_FAVORITE);
            mIntent.putExtras(mBundle);
            startActivityForResult(mIntent, ActivityStartRequestCode.ADD_FAVORITE);
        }
    });

//activity onCreate method, which trying to open

public void onCreate(Bundle bundle) {
        super.onCreate(bundle);

        Log.d(TAG, "onCreate");
//here, when i am going to get it, i see that bundle argument is null

I tried to make it over the activity, but it says me that: Call requires API level 16. Because i use API 14 as minumum.

 getActivity().startActivityForResult(mIntent, ActivityStartRequestCode.ADD_FAVORITE, mBundle);

Please provide working solution. Thanks

AEMLoviji
  • 3,217
  • 9
  • 37
  • 61

1 Answers1

1

To receive the data from started activity use getIntent() in onCreate method.

That is,

 Intent mIntent = new Intent(getActivity(), CategoriesActivity.class);
            mIntent.putExtra(BundleConstants.OPERATION_TYPE, OperationTypes.ADD_FAVORITE);
            startActivityForResult(mIntent, ActivityStartRequestCode.ADD_FAVORITE);

to receive, use in onCreate():

Intent received = getIntent();
int var = received.getInt(....);

Anyway, if you namely want the bundle, use something like this: https://stackoverflow.com/a/16073980/1979882 or this: https://stackoverflow.com/a/31021165/1979882

Community
  • 1
  • 1
Vyacheslav
  • 26,359
  • 19
  • 112
  • 194