1

When I my app is launched I am showing a splash screen. That page is been shown for 10 sec, running on a thread.

When it switches over to new activity on a result I want o hit a URL in server and I will be getting a return value which I can use for my further implements.

Here is my code:

private final int SPLASH_DISPLAY_LENGHT = 1000;

new Handler().postDelayed(new Runnable()
        {
            @Override
            public void run() 
            {
                Log.e("Handler ","run");
                Intent myIntent = new Intent(getApplicationContext(), CaptureActivity.class);
                startActivityForResult(myIntent, imgDL);
                finish();
            }
        }, SPLASH_DISPLAY_LENGHT);



public void onActivityResult(int requestCode, int resultCode, final Intent data) 
      {
          super.onActivityResult(requestCode, resultCode, data);
          if (requestCode == imgDL) 
          {     
              Log.e("onActivity Result","");
              urlHitMethod("http://XXXXXXXXXXXXXXXXXX.com/banner_scan");
          }
      }

But here the onActivityResult is not called. How to fix this?

double-beep
  • 5,031
  • 17
  • 33
  • 41
Siva K
  • 4,968
  • 14
  • 82
  • 161

4 Answers4

4

Also, please note than if you base activity (the one calling startActivityForResult) can't use the flag noHitory in the manifest.

If you do so, onActivityResult will never be called.

Snicolas
  • 37,840
  • 15
  • 114
  • 173
1

try this

Intent myIntent = new Intent(activity.this, CaptureActivity.class);

and

@Override
public void onActivityResult(int requestCode, int resultCode, final Intent data) 
      {
          super.onActivityResult(requestCode, resultCode, data);
          if (requestCode == imgDL) 
          {     
              Log.e("onActivity Result","");
              urlHitMethod("http://XXXXXXXXXXXXXXXXXX.com/banner_scan");
          }
          if(resultCode==RESULT_OK)
      {
    Log.e("onActivity Result","come in onactivity result ok"); 

      }
          else
          {
    Log.e("onActivity Result","come in onactivity result with error"); 

      }



      }
Niranj Patel
  • 32,980
  • 10
  • 97
  • 133
1

If you are using onActivityResult, then you should not finish the activity when starting with intent otherwise it will crash the app. Thanks.

javapluto
  • 11
  • 1
0

In the CaptureActivity.class you have to set the result and then check in the onActivityResult in the First Activity the result code

In the CaptureActivity.class it should be like the following

 Intent in = new Intent();
    setResult(1,in);//Here I am Setting the Requestcode 1, you can put according to your requirement
    finish();
Shaista Naaz
  • 8,281
  • 9
  • 37
  • 50
  • Actually your comment is wrong. You don't set the requestCode, but the resultCode. And if I'm right, you could use Activity.RESULT_CANCELLED and Activity.RESULT_OK – mDroidd Aug 20 '13 at 15:54
  • My problem is that when you set the result of the activity to RESULT_OK, onActivityResult on the waiting activity was never called.When i changed to result value to 1 it worked. – Ilker Baltaci Feb 17 '14 at 08:18
  • 1
    -1. @mDroidd is right - you aren't setting the `requestCode`, you're passing a literal value in for `resultCode`, which actually corresponds to `RESULT_FIRST_USER`, not `RESULT_OK` – kolosy Apr 24 '14 at 15:24