[android-developers] Re: dealing with multiple activities

2008-12-29 Thread Andrew Stadler

This suggestion is correct- use the intent extras to send your own
data back-and-forth to the sub-launched activity.  Here are a couple
of things to consider:

(1)  If at all possible, the sub activity should not crash if expected
extras data is not found in the launching intent.  (Null pointer
exceptions are very common in this area.)  Launch with defaults if
possible;  Or finish() immediately (perhaps after a dialog warning.)
This makes it more resilient to unexpected launch conditions like
being launched from AnyCut, launched by a testing monkey, or your own
test code.

(2)  When passing data between activities, be extremely careful that
you don't include references to the activity objects themselves - this
can cause memory leaks.  Make sure that any objects you pass between
activities are self-contained.  (The common mistake here is to use
inner classes that are not static.)

Hope this helps.

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



[android-developers] Re: dealing with multiple activities

2008-12-28 Thread gstavrev

You are on the right track. I`m not an expert, but I was playing with
the same thing yesterday. You use the addExtras function for the
Intent, but you use a Bundle as an argument. In the bundle I believe
you can store values as an associative aray or hash. You then extract
the bundle and the associated element from the other activity. This
worked for but for simple things like integers and strings. Hope this
helps.

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



[android-developers] Re: dealing with multiple activities

2008-12-27 Thread Mark Murphy

Sarath Kamisetty wrote:
 Is there any example out there where one activity creates another
 activity and the new activity returns something to the old one ? In my
 application, when user clicks on a button, I need to move to a new
 activity where I display a list of items and once the user selects one
 of them I have to pass that data value back to the first activity
 where it is displayed in a text field. I see that the notepad v3
 example comes close but not quite.

Search for startActivityForResult(). In your SDK samples/ directory, you
will find a few matches:

./ApiDemos/src/com/example/android/apis/app/ReceiveResult.java
./ApiDemos/src/com/example/android/apis/app/LaunchingPreferences.java
./ApiDemos/src/com/example/android/apis/app/RedirectMain.java

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com
_The Busy Coder's Guide to Android Development_ Version 1.9 Available!

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



[android-developers] Re: dealing with multiple activities

2008-12-27 Thread Emmanuel

Call the second activity with startActivityForResult, add a SetResult
( ... ) with your result just before calling finish in your second
activity, then in your first activity, onActivityResult will be
called, where you can treat your results.

Hope it helps,

Emmanuel
http://androidblogger.blogspot.com/

On Dec 27, 7:30 pm, Sarath Kamisetty sarath.kamise...@gmail.com
wrote:
 Hi,

 Is there any example out there where one activity creates another
 activity and the new activity returns something to the old one ? In my
 application, when user clicks on a button, I need to move to a new
 activity where I display a list of items and once the user selects one
 of them I have to pass that data value back to the first activity
 where it is displayed in a text field. I see that the notepad v3
 example comes close but not quite.

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



[android-developers] Re: dealing with multiple activities

2008-12-27 Thread Sarath Kamisetty

Hi,

Thanks for the tips. Is it possible to pass an arbitrary object to the
child activity and back ? The examples I saw were setting stuff inside
the intent itself. For example, from parent to child, I query a
content provider that returns a bunch or rows displayed by list
activity. Once user selects one of the items from the list, i want to
get the corresponding row from the list adapter and pass it to child
activity. So, I was hoping to do something like below:

protected void onListItemClick(ListView l, View v, int position, long id) {
...
...
Intent i = new Intent(this, ChildActivity.class);
i.putExtra(ChildActivity.KEY_ITEM, myAdapter.getItemId((int)id));
startActivityForResult(i, ENTRY_CREATE);
...
...
}

My child activity might not also need to send back an object to the
parent (i am not sure if it is needed at this point in my app. but ..)
but not sure if it can be done.

Thanks,
Sarath

On Sat, Dec 27, 2008 at 6:05 PM, Emmanuel emmanuel.ast...@gmail.com wrote:

 Call the second activity with startActivityForResult, add a SetResult
 ( ... ) with your result just before calling finish in your second
 activity, then in your first activity, onActivityResult will be
 called, where you can treat your results.

 Hope it helps,

 Emmanuel
 http://androidblogger.blogspot.com/

 On Dec 27, 7:30 pm, Sarath Kamisetty sarath.kamise...@gmail.com
 wrote:
 Hi,

 Is there any example out there where one activity creates another
 activity and the new activity returns something to the old one ? In my
 application, when user clicks on a button, I need to move to a new
 activity where I display a list of items and once the user selects one
 of them I have to pass that data value back to the first activity
 where it is displayed in a text field. I see that the notepad v3
 example comes close but not quite.

 Thanks,
 Sarath
 


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