I have tried to share betweeb two simple activities:

On "parent" activity, I'll start ImageCapture Activity:

                    Intent cameraIntent = new Intent();
                    cameraIntent.setClass(this, ImageCapture.class);
                    cameraIntent.putExtra("cameraData", "null"); //not sure why
this is here?
                    startActivityForResult(cameraIntent, 1);


    @Override
    protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
        CharSequence text = "onActivityResult requestCode " +
requestCode + " resultCode " + resultCode + " data " + data;
        int duration = Toast.LENGTH_LONG;
        Toast toast = Toast.makeText(this, text, duration);
        toast.show();
    }

And on camera Activity (I have inner class which implements
PictureCallback):

       @Override
        public void onPictureTaken(byte[] data, Camera camera) {
            try {
                Intent resultIntent = new Intent();
                resultIntent.putExtra("cameraData", data);
                setResult(Activity.RESULT_OK,resultIntent);
                finish();
            } catch (Exception ex) {
                setResult(Activity.RESULT_CANCELED);
                finish();
            }
        }


It seems that onActivityResult method is never called, what am I
missing here? Camera activity is closed and first activity is shown
again but onActivityResult is not called.
It works perfectly fine (onActivityResult is called and toast is
displayed) if do following on camera intent:

@Override
        public void onPictureTaken(byte[] data, Camera camera) {
            try {
                //Intent resultIntent = new Intent();
                //resultIntent.putExtra("cameraData", data);
                setResult(Activity.RESULT_OK);
                finish();
            } catch (Exception ex) {
                setResult(Activity.RESULT_CANCELED);
                finish();
            }

With code above Activity.RESULT_OK (-1) is returned to
onActivityResult method.
I'm testing with HTC Hero.

Cheers
Olli

On 7 elo, 17:48, elpix1 <[email protected]> wrote:
> Another way to share data between activities in the same process
> is to use the Application class:
>
> http://developer.android.com/reference/android/app/Application.html
>
> You have to specify the name of your Application class in the
> manifest and the framework will create only an instance of this
> class, which will live while the application process is running.
>
> In any activity, you can get the reference for your application
> instance using:
>
> Application a = getApplication();
>
> On Jul 22, 10:49 am, Per Sandström <[email protected]> wrote:
>
> > So far I have been using SharedPreferences to share data between
> > activities. But I would very much like to find a better way. I would
> > simply like both Activity1 and Activity2 to share Object1. Activity1
> > will create Object1 and then start Activity2. What is the smartest way
> > to give Activity2 a pointer to Object1?
>
> > To summarize: Activities don't have constructors! How do I send data
> > to them from their parent activity???
>
> > Regards,
> > Per Sandström

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to