onActivityResult not being called when launching another app

239 views Asked by At

I am trying to call another app through intent, the app is called but the onActivityResult is not being called. Could someone please help me on this? Below is my code:

public class EncryptCommandActivity extends Activity{

EncryptionFactory encryptionFactory = new EncryptionFactory();

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.encrpyt_command_activity);
    ActivityContexts.setEncryptCommandActivityContext(this);

    Intent intent = new Intent("asd.com.qweapi.MAIN_ACTIVITY");

    Bundle bundle = new Bundle();

    bundle.putInt("Function", 1006);
    bundle.putString("MSG", MQTTFactory.getById());
    intent.putExtras(bundle);

    startActivityForResult(intent, 0);

    finish();

}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent pData)
{
    super.onActivityResult(requestCode,resultCode,pData);
    Log.d("Encrypt","Inside");  //not called
    Toast.makeText(ActivityContexts.getMainActivityContext(),"encrypt", Toast.LENGTH_LONG).show(); //not called

}

}
2

There are 2 answers

0
ThaiPD On BEST ANSWER

You should remove finish() in onCreate() because it will finish activity and then it's no longer to exist, since can not fire onActivityResult()

0
Kazuki On

move finish() to onActivityResult from onCreate