0

My App1 launch App2:

case R.id.launch_button: {
  try {
       Intent intent = getPackageManager().getLaunchIntentForPackage("com.app1");
       intent.putExtra("Price", getAmount());
       intent.putExtra("Description", getProductId());
       startActivityForResult(intent, PAYMENT_REQUEST);
      } catch (ActivityNotFoundException e) {
        e.printStackTrace();
        Log.i(TAG, "Activity not found" );
        }
        break;
    }

When App2 finish processing should return RESULT_OK or RESULT_CANCELED:

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        Log.i(TAG, "onActivityResult " + requestCode + " " + resultCode + " " + data);
        if (requestCode == PAYMENT_REQUEST) {
            if (resultCode == Activity.RESULT_OK) {
                Toast.makeText(this, "Payment success", Toast.LENGTH_LONG).show();
            }
            if (resultCode == Activity.RESULT_CANCELED) {
                Toast.makeText(this, "Payment fail", Toast.LENGTH_LONG).show();
            }
        }
    }

but RESULT_CANCELED appears immediately when the App2 launch. Why am I receiving RESULT_CANCELED before even the App2 launch? What I'm doing wrong?

App2 return result code:

@Override
public void onPaymentSuccess() {
    activity.setResult(Activity.RESULT_OK);
    activity.finish();
}
@Override
public void onPaymentFail() {
    activity.setResult(Activity.RESULT_CANCELED);
    activity.finish();
}

I also dont receive any result when App2 finish..

Note: App2 use Fragment

Aspir
  • 149
  • 9
  • You should call .setResult() on a new Intent. And call finish() as it is. – blackapps Sep 16 '20 at 11:21
  • Why? It is not nessesary because I dont wonna pass any data to App1 – Aspir Sep 16 '20 at 12:26
  • problem solved: https://stackoverflow.com/questions/10048813/android-onactivityresult-called-early/10075762 i use intent.setClassName() instead getPackageManager – Aspir Sep 16 '20 at 12:29

0 Answers0