我试图通过意图调用另一个应用程序,调用该应用程序,但未调用onActivityResult。有人可以帮我这个吗? 以下是我的代码:
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
}
}
答案 0 :(得分:2)
您应该移除finish()
中的onCreate()
因为它将完成活动然后它不再存在,因为无法触发onActivityResult()
答案 1 :(得分:0)
从onCreate
移动finish()到onActivityResult