Skip to content Skip to sidebar Skip to footer

Android On Activity Result Always Return 0 And Null Intent

I tried almost all solutions found from the net and still can't solve my problem. Would anyone please help with the following codes? I really can't make it work. Even if I tried to

Solution 1:

Before call the finish() method in your child activity,add the below code:

setResult(RESULT_OK);

Fllowing is new: 1、Add new variable:

Context mContext;

2、Change your adapter constructor:

public CategoryAdapter(Context context,CategoryModel[] list) {
    mContext = context;
    inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

3、Change finish() in adapter to:

((Activity)mContext).finish();

4、Replace your adapter's definition in your parent activity with the construction mentioned in Step 2


Solution 2:

Finally I figured it out!!!

The original on touch listener I wrote has been fired three times, that's why it was unable to retrieve the actual return result.

Solved it by this --> Setting a spinner onClickListener() in Android

private View.OnTouchListener Spinner_OnTouch = new View.OnTouchListener() {
    public boolean onTouch(View v, MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_UP) {

            if (v.getId() == R.id.spinnerCategory) {
                Bundle bundle = new Bundle();
                bundle.putInt("CategoryId", categoryId);
                Intent intent = new Intent(mContext, CreatePostActivity_Category.class);
                intent.putExtras(bundle);
                startActivityForResult(intent, Variables.CREATEPOST_CATEGORY_ACTIVITY_REQUEST_CODE);
            }
        }
        return true;
    }
};

Everything works. Thanks all for the suggested and correct answers.


Post a Comment for "Android On Activity Result Always Return 0 And Null Intent"