3
votes

my Class A calls a startActivityForResult: class A is activitygroup in the one tab of tabactivity

Intent intent = new Intent(this, ClassB.class);
startActivityForResult(intent, "STRING");

ClassB is a common activity ,not in the tabactivity,it is alone

Intent intent = this.getIntent();
intent.putExtra("SOMETHING", "EXTRAS");
this.setResult(RESULT_OK, intent);
finish();

but in Class A onactivityResult not receive anying,not excute.if i put classA out of the tabactivity,my app is ok. i have read

How to setResult() for a TabActivity which contains activity for tabs

How to return a result (startActivityForResult) from a TabHost Activity?

but not solve my problem,can somebody an give some advice ,code is more better,thank you

edit: in class A i add:

public class UpdateImageBroadcastReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {

            Log.i("temp","34353");


        }
    }



    /* (non-Javadoc)
     * @see android.app.Activity#onPause()
     */
    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        super.onPause();
        unregisterReceiver(updateImageBroadcastReceiver);

    }

    /* (non-Javadoc)
     * @see android.app.Activity#onResume()
     */
    @Override
    protected void onResume() {
        // TODO Auto-generated method stub
        super.onResume();

        updateImageFilter = new IntentFilter("ACTION_CHANGE_TAB");
        updateImageBroadcastReceiver = new UpdateImageBroadcastReceiver();
        registerReceiver(updateImageBroadcastReceiver, updateImageFilter);


    }

in class B:

   Intent intent = new Intent("ACTION_CHANGE_TAB");
                        intent.putExtra("path", f.getAbsolutePath());
                        sendBroadcast(intent);

                    //  FileListSelectActivity.this.setResult(RESULT_OK, intent);
                        finish();

but i cannot print: Log.i("temp","34353");

3

3 Answers

1
votes

Try using broadcast receivers. You can override onStop() in activity B, broadcast an event from activity B and listen in activity A.

1
votes

Don't know if it is a the best method but currently I use a class that I call memory to pass objects between the activities.

public class Memory {
    public static Object objectToPass = null;
}
1
votes

I can't found problem exactly without source code, but it could be one of next situation

1) Root activity for tabhost doesn't receive onActivityResult. Then you should call overriden onActivityResult in Activity inside TabHost

2) Another situation: Activity inside tabhost doesn't receive onActivityResult. Only focused activity will receive any actions inside ActivityGroup. You should place focus to some view inside it, then you will receive actions.