OnActivityResult not called for startActivityForResult

I have MainActivity with an options menu with the 'settings' element.

When I launch SettingsActivity , everything works fine until we click on save and try completing SettingsActivity . This activity ends, but appears to close the parental activity. I am working on this in Eclipse. Eclipse says something is still working because it allows me to press the stop button. I have a timer thread running in MainActivity , but I tested this without this thread and it still doesn't return to onActivityResult() .

I run SettingsActivity this way:

 public static final int ACTIVITY_CREATE = 1; @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.settings: try { Intent intent = new Intent(this, SettingsActivity.class); startActivityForResult(intent, ACTIVITY_CREATE); } catch (Exception e) { Log.e(TAG, e.getMessage()); finish(); } return true; default: return super.onOptionsItemSelected(item); } } 

I expect that finish () in SettingsActivity will return me to this function, but it is not. I have a breakpoint set here and it never gets here:

  @Override protected void onActivityResult(int requestCode, int resultCode, Intent intent) { super.onActivityResult(requestCode, resultCode, intent); switch (requestCode) { case (ACTIVITY_CREATE): { if (resultCode == RESULT_OK) { } break; } } } 

Here is a simple SettingsActivity parameter:

  public class SettingsActivity extends Activity implements View.OnClickListener { private Button save; @Override public void onCreate(Bundle b) { super.onCreate(b); setContentView(R.layout.settings); save = (Button) findViewById(R.id.save); save.setOnClickListener(this); return; } @Override public void onClick(View v) { switch (v.getId()) { case R.id.save: Intent intent = new Intent(); intent.putExtra("ip", ipText.getText().toString()); setResult(RESULT_OK, intent); finish(); break; default: break; } return; } } // public class SettingsActivity extends Activity { 

In startup mode, the main activity is set to "standard".

My question is: why am I not returning to onActivityResult () in the calling activity?

Thanks Bob

Here is the manifest file:

  <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.MyStuff" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".CTNet" android:label="@string/app_name" android:screenOrientation = "fullSensor" android:configChanges = "orientation|screenSize|keyboardHidden" android:launchMode="singleTask" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".SettingsActivity" > </activity> </application> <uses-sdk android:minSdkVersion="8" /> <!-- after targetSdkVersion --> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-feature android:glEsVersion="0x00020000" android:required="true" /> </manifest> 

Trying to add a detailed logarithm here:

  06-30 12:18:58.292: I/System.out(16197): Sending WAIT chunk 06-30 12:18:58.292: W/ActivityThread(16197): Application com.MyStuff is waiting for the debugger on port 8100... 06-30 12:18:58.300: I/dalvikvm(16197): Debugger is active 06-30 12:18:58.495: I/System.out(16197): Debugger has connected 06-30 12:18:58.495: I/System.out(16197): waiting for debugger to settle... 06-30 12:18:58.698: I/System.out(16197): waiting for debugger to settle... 06-30 12:18:58.901: I/System.out(16197): waiting for debugger to settle... 06-30 12:18:59.097: I/System.out(16197): waiting for debugger to settle... 06-30 12:18:59.300: I/System.out(16197): waiting for debugger to settle... 06-30 12:18:59.503: I/System.out(16197): waiting for debugger to settle... 06-30 12:18:59.706: I/System.out(16197): waiting for debugger to settle... 06-30 12:18:59.901: I/System.out(16197): waiting for debugger to settle... 06-30 12:19:00.104: I/System.out(16197): waiting for debugger to settle... 06-30 12:19:00.307: I/System.out(16197): waiting for debugger to settle... 06-30 12:19:00.511: I/System.out(16197): debugger has settled (1476) 06-30 12:19:00.722: D/SOV(16197): MainActivity::onCreate 06-30 12:19:01.003: D/CTNet(16197): creating view 06-30 12:19:01.003: D/CTNet(16197): view created 06-30 12:19:01.065: I/System.out(16197): CTNet: starting 06-30 12:19:01.128: I/System.out(16197): BMA254 Acceleration Sensor 06-30 12:19:01.128: I/System.out(16197): vendor = Bosch Sensortec 06-30 12:19:01.128: I/System.out(16197): version = 42602 06-30 12:19:01.128: I/System.out(16197): maximum range = 19.613300 06-30 12:19:01.136: I/System.out(16197): min delay = 10000 06-30 12:19:01.136: I/System.out(16197): power = 0.130000 06-30 12:19:01.136: I/System.out(16197): resolution = 0.038307 06-30 12:19:01.136: I/System.out(16197): type = 1 06-30 12:19:01.136: I/System.out(16197): MS-3E (YAS530) Magnetic Sensor 06-30 12:19:01.136: I/System.out(16197): vendor = Yamaha Corporation 06-30 12:19:01.143: I/System.out(16197): version = 42602 06-30 12:19:01.143: I/System.out(16197): maximum range = 800.000000 06-30 12:19:01.143: I/System.out(16197): min delay = 10000 06-30 12:19:01.143: I/System.out(16197): power = 4.000000 06-30 12:19:01.143: I/System.out(16197): resolution = 0.300000 06-30 12:19:01.143: I/System.out(16197): type = 2 06-30 12:19:01.151: I/System.out(16197): MS-x Orientation Sensor 06-30 12:19:01.151: I/System.out(16197): vendor = Yamaha Corporation 06-30 12:19:01.151: I/System.out(16197): version = 42602 06-30 12:19:01.151: I/System.out(16197): maximum range = 360.000000 06-30 12:19:01.151: I/System.out(16197): min delay = 10000 06-30 12:19:01.151: I/System.out(16197): power = 0.000000 06-30 12:19:01.151: I/System.out(16197): resolution = 1.000000 06-30 12:19:01.151: I/System.out(16197): type = 3 06-30 12:19:01.151: I/System.out(16197): AL3201 Light Sensor 06-30 12:19:01.151: I/System.out(16197): vendor = LITEON 06-30 12:19:01.151: I/System.out(16197): version = 42602 06-30 12:19:01.159: I/System.out(16197): maximum range = 0.000000 06-30 12:19:01.159: I/System.out(16197): min delay = 0 06-30 12:19:01.159: I/System.out(16197): power = 0.000000 06-30 12:19:01.159: I/System.out(16197): resolution = 0.000000 06-30 12:19:01.159: I/System.out(16197): type = 5 06-30 12:19:01.159: I/System.out(16197): Auto Rotation Sensor 06-30 12:19:01.159: I/System.out(16197): vendor = Samsung Electronics 06-30 12:19:01.159: I/System.out(16197): version = 1 06-30 12:19:01.159: I/System.out(16197): maximum range = 255.000000 06-30 12:19:01.159: I/System.out(16197): min delay = 0 06-30 12:19:01.167: I/System.out(16197): power = 0.000000 06-30 12:19:01.167: I/System.out(16197): resolution = 0.000000 06-30 12:19:01.167: I/System.out(16197): type = 15 06-30 12:19:01.167: E/SensorManager(16197): thread start 06-30 12:19:01.167: D/SensorManager(16197): registerListener :: handle = 1 name= BMA254 Acceleration Sensor delay= 200000 06-30 12:19:01.253: D/CTNet(16197): onStart 06-30 12:19:01.261: D/CTNet(16197): onResume 06-30 12:19:01.487: D/SV(16197): surfaceCreated 06-30 12:19:01.487: D/SV(16197): surfaceChanged 06-30 12:19:08.190: W/Choreographer(16197): Already have a pending vsync event. There should only be one at a time. 06-30 12:19:08.222: D/CTNet(16197): onPause 06-30 12:19:08.245: D/SensorManager(16197): unregisterListener:: 06-30 12:19:08.245: D/Sensors(16197): Remain listener = Sending .. normal delay 200ms 06-30 12:19:08.245: I/Sensors(16197): sendDelay --- 200000000 06-30 12:19:08.245: D/SensorManager(16197): JNI - sendDelay 06-30 12:19:08.245: I/SensorManager(16197): Set normal delay = true 06-30 12:19:08.323: E/ViewRootImpl(16197): sendUserActionEvent() mView == null 06-30 12:19:08.487: D/settings(16197): 192.168.1.200 06-30 12:19:08.487: D/settings(16197): 9072 06-30 12:19:08.979: D/SV(16197): surfaceDestroyed 06-30 12:19:09.089: D/CTNet(16197): onStop 06-30 12:19:10.682: D/settings(16197): save clicked 06-30 12:19:10.729: W/Choreographer(16197): Already have a pending vsync event. There should only be one at a time. 06-30 12:19:10.948: W/IInputConnectionWrapper(16197): showStatusIcon on inactive InputConnection 06-30 12:19:11.104: D/SOV(16197): MainActivity::onDestroy 
0
source share
4 answers

I believe because launchMode , view it in AndroidManifest

Try it with singleTop

http://developer.android.com/guide/topics/manifest/activity-element.html#lmode

[Changed]

Do this and tell us what happens when you click in the settings window.

 @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.settings: Intent intent = new Intent(this, SettingsActivity.class); startActivityForResult(intent, ACTIVITY_CREATE); break; } return super.onOptionsItemSelected(item); } 
0
source

Try setting mainActivity as

  android:launchMode="singleTask" 

in your AndroidManifest.

0
source

Try changing the method from protected to public

0
source

I found a problem. I had a finish () at the end of the MainActivity onStop () function.

0
source

Source: https://habr.com/ru/post/971813/


All Articles