Search code examples
androidandroid-activityonactivityresultonresume

Why is OnActivityResult() never called?


This is how I start the Tab Activity

  Intent i = new Intent("walk.me.TAB");
        startActivityForResult(i, STATIC_RESULT);

Note: STATIC_RESULT=-1 or RESULT_OK;.

This is how I finish the Tab activity

((Button)viewItem.findViewById(R.id.gotherefav)).setOnTouchListener(new OnTouchListener(){

    @Override
    public boolean onTouch(View v, MotionEvent event) {

        if(ime!=null)
        {

        b.putString("ime",ime.toString());
        b.putIntArray("koordinati&kategorija", coordAndCat );

        b.putBoolean("klik", true);

        FinishWithResult(b);
        }
        return false;
    }});



public void FinishWithResult(Bundle b)
{
    Intent i = getIntent();
    i.putExtras(b);
    setResult(Activity.RESULT_OK, i);
     Log.i("in FINISH", "settig Activity Result");  
    finish();   
}

And here is my OnActivityResult implementation:

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          Log.i("in OnActivityResult", "Activity Result");  
          Toast.makeText(getBaseContext(), "DOJDE", Toast.LENGTH_LONG).show();
        super.onActivityResult(requestCode, resultCode, data);

          Log.i("in OnActivityResult", "Activity Result");
          if (requestCode == STATIC_RESULT) {
                 if (resultCode == RESULT_OK) {

           Toast.makeText(getBaseContext(), "DOJDE BUNDLE", Toast.LENGTH_LONG).show();
           Bundle preferenciOdTab = data.getExtras();
           if(preferenciOdTab !=null && preferenciOdTab.getBoolean("klik", true))
                  {
                    mapView = (MapView)findViewById(R.id.map);
                     isFavorite=preferenciOdTab.getBoolean("klik");
                  drawFavorite(preferenciOdTab.getString("ime"),preferenciOdTab.getIntArray("koordinati&kategorija"));
                  }
                 }}

Why is onActivityResult never called and directly goes to OnResume() regardless of the documentation garantees that OAR will be called before OR? What I'm doing wrong? I dont have stated in manifest xml

singleInstance

or

singleTask

for the Main activity.


Solution

  • You say STATIC_RESULT is -1?

    The requestCode has to be a positive integer.

    startActivityForResult()

    Parameters

    intent The intent to start.

    requestCode If >= 0, this code will be returned in onActivityResult() when the activity exits.