Why isn't onActivityResult called in Android?

When I launch my application, I display a splash screen. This page is shown for 10 seconds, works in a stream.

When it switches to a new action with the result, I want to click the URL on the server and I will get a return value that I can use for my further tools.

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 onActivityResult not called. How to fix it?

+1
android android-activity result onactivityresult
source share
4 answers

In CaptureActivity.class you need to set the result and then check onActivityResult in the first action the result code

In CaptureActivity.class it should look like this

  Intent in = new Intent(); setResult(1,in);//Here I am Setting the Requestcode 1, you can put according to your requirement finish(); 
0
source share

Also note that if you use basic activity (the one who calls startActivityForResult), you cannot use the noHitory flag in the manifest.

If you do this, onActivityResult will never be called.

+4
source share

try it

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"); } } 
+1
source share

If you use onActivityResult, then you should not complete the action at startup with the intent, otherwise this will cause the application to crash. Thanks.

+1
source share

All Articles