来自HomeActivity我试图从CreateProfileActivity获得结果.这是我开始活动的方法
Intent createProfile = new Intent(this,CreatePreacherActivity.class); startActivityForResult(createProfile,1);
这里是HomeActivity中onActivityResult方法的实现:
@Override protected void onActivityResult(int requestCode,int resultCode,Intent data) { if (requestCode == 1) { Log.d("DEV","HomeActivity is reciving data"); if (resultCode == RESULT_OK) { // this code here execute at the second call // but why there are two calls when i just call setResult once??? User user = new User(); String[] userInfo = data.getStringArrayExtra("preacher"); //parsing and saving and database code... Log.d("DEV","HomeActivity data received->"+user); CurrentUser.set(this,user); fillCurrentUserInforms(); } // if while searching for the preacher list // and none was found on database. Then tell the user // to create a new profile else if (resultCode == RESULT_CANCELED) { Intent createPreacherIntent = new Intent( this,CreatePreacherActivity.class ); startActivityForResult(createPreacherIntent,1); } }
当我完成并按下CreateProfileActivity中的保存时,我将把数据发送回HomeActivity:
**private void createProfile() { // some parsing and inserting the new data code.. User u = new User(); u.setName(newPreacher.getName()); u.setLastName(newPreacher.getLastName()); u.setId(newPreacher.getId()); u.setSex(newPreacher.getSex()); CurrentUser.set(this,u); if (getParent() == null) { setResult(RESULT_OK,createPreacherDataIntent(newPreacher)); } else { getParent().setResult(RESULT_OK,createPreacherDataIntent(newPreacher)); } Log.d("DEV","Exiting from CreatePreacherActivity"); finish(); }**
setResult方法在CreateProfileActivity上调用一次,但由于某些未知原因,当数据到达HomeActivity.onActivityResult方法时,执行两次. requestCode = 0的第一个结果和requestCode = 1的第二个结果.之后,HomeActivity.onActivityResult执行,自第一次调用requestCode为0以来,CreateProfileActivity再次出现.
那么为什么onActivityResult会执行两次?
第一次通话时0为0,第二次通话为1?
注意:我已经阅读了以下问题,看看我是否做错了但我能看到它:
Android onActivityResult is always 0
更新:
我的清单
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="jwutils.einers.informedeserviciotj" > <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".Activities.HomeActivity" android:label="Inform de Servicio" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".Activities.inform.InformEditableActivity"></activity> <activity android:name=".Activities.preacher.CreatePreacherActivity" android:label="Crear publicador"/> <activity android:name=".Activities.preacher.PreachersListActivity" android:label="Usuarios" /> </application> </manifest>
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。