Re: [android-developers] parcelable again: passing object BACK through activity stack

2011-09-25 Thread John Goche
On Fri, Sep 23, 2011 at 9:53 PM, Streets Of Boston
flyingdutc...@gmail.comwrote:

 1) The onActivityResult will have a result-code of RESULT_CANCELED and its
 'Intent data' parameter will be null.

 2) Yes, you can pass back any Intent, even the one that started the
 child-activity. You don't need to create a brand new one.

 When an Intent is passed back or forth between Activities (starting an
 activity / setResult+finishing), the other end (getIntent() / Intent in the
 onActivityResult) doesn't get the exact same *instance *of the Intent.
 Instead, it'll get a copy of it as an Intent with the exact same contents.
 As a comparison: Intents are passed by copy, not by value or reference :-)


Thanks, that makes sense. However I have one more question if you don't mind
asking concerning
onRestart(), onStart() and onActivityResult(). I am using onActivityResult()
in acitivty A to store data
from acitivty B in a database. Is it safe to refresh the screen widgets with
the data in onActivityResult()
or is it better to do this inside onStart()? Plus, which gets called first,
the asynchronous onActivityResult()
or onStart(). This is what has been puzzling me lately.

Thanks for your insight,

John Goche

-- 
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

Re: [android-developers] parcelable again: passing object BACK through activity stack

2011-09-25 Thread TreKing
On Sun, Sep 25, 2011 at 6:26 AM, John Goche johngoch...@googlemail.comwrote:

 Is it safe to refresh the screen widgets with the data in
 onActivityResult() or is it better to do this inside onStart()?


It is safe and preferred - how would you know you were coming back from a
result in onStart() ?


 Plus, which gets called first, the asynchronous onActivityResult() or
 onStart(). This is what has been puzzling me lately.


Put a log statement or break point in each and see.

-
TreKing http://sites.google.com/site/rezmobileapps/treking - Chicago
transit tracking app for Android-powered devices

-- 
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

Re: [android-developers] parcelable again: passing object BACK through activity stack

2011-09-23 Thread TreKing
On Thu, Sep 22, 2011 at 7:15 PM, John Goche johngoch...@googlemail.comwrote:

 Not sure how to try this out on the emulator.


F12 or F11 or something causes the emulator to rotate. See the emulator
section in the Docs.


 Since the Intent is returned to the parent activity inside
 onActivityResult, what is the difference in using setResult and using
 putExtra in Activtity B on the Intent to pass back a custom result parameter
 to Activity A?


Difference compared to what?

-
TreKing http://sites.google.com/site/rezmobileapps/treking - Chicago
transit tracking app for Android-powered devices

-- 
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

Re: [android-developers] parcelable again: passing object BACK through activity stack

2011-09-23 Thread Streets Of Boston
You can try this on the emulator. Hit Ctrl+F11 and you'll 'rotate' the 
device.

setResult does not immediately return results back to its parent activity 
(You can call setResult many times: only the last call to setResult will be 
effective, superseding all previous calls)
The Intent you use when calling setResult will be the same Intent passed to 
the parent's implementation of onActivityResult later.
Only when your child-activity finishes (call 'finish()' or the user hits the 
Back-key/button), then onActivtyResult will be called with same the Intent 
that was used by the last call to setResult.

-- 
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

Re: [android-developers] parcelable again: passing object BACK through activity stack

2011-09-23 Thread John Goche
On Fri, Sep 23, 2011 at 3:27 PM, Streets Of Boston
flyingdutc...@gmail.comwrote:

 You can try this on the emulator. Hit Ctrl+F11 and you'll 'rotate' the
 device.


Yes, I saw the problem pop up with my onRestart() called when I wasn't
expecting it.

I can see the problem here with onRestart() being called when I didn't
expect it to (for all activities on
the activity stack?) when the screen is rotated. Thanks for pointing it out.
I can also see the emulator
bug whereby I have to relaunch my application to exit landscape mode and get
back to portrait mode.

setResult does not immediately return results back to its parent activity
 (You can call setResult many times: only the last call to setResult will be
 effective, superseding all previous calls)


This part is clear.


 The Intent you use when calling setResult will be the same Intent passed to
 the parent's implementation of onActivityResult later.
 Only when your child-activity finishes (call 'finish()' or the user hits
 the Back-key/button), then onActivtyResult will be called with same the
 Intent that was used by the last call to setResult.


What is not clear to me at this point from the documentation is:

1. if I don't pass an intent to setResult(), ie. use the one-parameter
version of setResult(), then will the null Intent be passed back to my
onActivityResult callback function?

2. Can I pass activity B's intent back to activity A by a call to setResult
and a call to finish() or do I have to create a new Intent in activity B
to pass back to activity A in my setResult?

Thanks,

John Goche

-- 
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

Re: [android-developers] parcelable again: passing object BACK through activity stack

2011-09-23 Thread TreKing
On Fri, Sep 23, 2011 at 1:38 PM, John Goche johngoch...@googlemail.comwrote:

 1. if I don't pass an intent to setResult(), ie. use the one-parameter
 version of setResult(), then will the null Intent be passed back to
 my onActivityResult callback function?

 2. Can I pass activity B's intent back to activity A by a call to setResult
 and a call to finish() or do I have to create a new Intent in activity B to
 pass back to activity A in my setResult?


This is the kind of stuff you learn by just trying it and seeing what
happens =)

-
TreKing http://sites.google.com/site/rezmobileapps/treking - Chicago
transit tracking app for Android-powered devices

-- 
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

Re: [android-developers] parcelable again: passing object BACK through activity stack

2011-09-23 Thread Streets Of Boston
1) The onActivityResult will have a result-code of RESULT_CANCELED and its 
'Intent data' parameter will be null.

2) Yes, you can pass back any Intent, even the one that started the 
child-activity. You don't need to create a brand new one.

When an Intent is passed back or forth between Activities (starting an 
activity / setResult+finishing), the other end (getIntent() / Intent in the 
onActivityResult) doesn't get the exact same *instance *of the Intent. 
Instead, it'll get a copy of it as an Intent with the exact same contents. 
As a comparison: Intents are passed by copy, not by value or reference :-)


-- 
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

Re: [android-developers] parcelable again: passing object BACK through activity stack

2011-09-22 Thread John Goche
Yes, the advice is indeed very good.

1. For the SQLite database bit, I think if parcelable is better than
serializable then
can I simplyparcel my nested object and write it as a row to the
database?
   I think SQLite is going to be faster than shared preferences.

2. However at this point I am wondering what the difference is
in using onActivityResult versus simply coding onRestart like so:

  @Override
  protected void onRestart() {

// should be returning from activity

   if (this.hasPushedActivityB) {
 foo();
   } else {
 bar();
  }
}

// further down

this.hasPushedActivityB = true;

// start new intent

startActivity(new Intent(...));

//...

private boolean hasPushedActivityB;

Anything wrong with this alternative approach?

--

3. I will look at result receiver even though I have used
a Globals class annotated with each parameter that needs
to be passed from screen to screen. Not sure, maybe using
result receiver is beter.

Thanks,

John Goche

On Thu, Sep 22, 2011 at 1:08 AM, Richard Schilling coderroa...@gmail.comwrote:

 This is some good sound advice.  If you don't want to
 use startActivityForResult and onActivityResult then you can store your data
 in some source of truth like the SQLite database, or even shared
 preferences if you just have a few data items.


 Richard


Streets of Boston wrote:


 1. Try to avoid Serializable. It is very slow compared to Parcelable.
 2. Take a look at startActivityForResult and onActivityResult.
 3. If you reeeaaally need to update activity A about events from activity
 B, consider putting your own subclass of ResultReceiver in the Intent's
 'extras'. Then activity B can call 'send(...)' on that ResultReceiver and
 this will be received in activity A as an 'onReceiveResult(...)' call-back.


-- 
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

Re: [android-developers] parcelable again: passing object BACK through activity stack

2011-09-22 Thread Streets Of Boston
Yes, a lot :)

Try out your code using 'hasPushedActivityB' and then rotate your phone or, 
if it has a physical keyboard, slide out the keyboard: 
The activities will be recreated and your 'hasPushedActivityB' of the new 
activity A will be false, but the new Activity B will be showing.

Just use onActivityResult.:)

-- 
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

Re: [android-developers] parcelable again: passing object BACK through activity stack

2011-09-22 Thread John Goche
On Thu, Sep 22, 2011 at 3:43 PM, Streets Of Boston
flyingdutc...@gmail.comwrote:

 Yes, a lot :)

 Try out your code using 'hasPushedActivityB' and then rotate your phone or,
 if it has a physical keyboard, slide out the keyboard:
 The activities will be recreated and your 'hasPushedActivityB' of the new
 activity A will be false, but the new Activity B will be showing.


Not sure how to try this out on the emulator.




 Just use onActivityResult.:)


OK, but one more thing is not clear from the documentation at
http://developer.android.com/reference/android/app/Activity.html
under Starting Activities and Getting Results which states: When an
activity exits, it can call
setResult(int)http://developer.android.com/reference/android/app/Activity.html#setResult%28int%29to
return data back to its parent.
Since the Intent is returned to the parent activity inside onActivityResult,
what is the difference in using setResult and using putExtra in Activtity B
on the Intent to pass back a custom result parameter to Activity A?

(There is an example here:
http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/SendResult.html
and then there is the NotesList application.)

Thanks,

John Goche

-- 
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

Re: [android-developers] parcelable again: passing object BACK through activity stack

2011-09-21 Thread TreKing
On Tue, Sep 20, 2011 at 5:38 PM, John Goche johngoch...@googlemail.comwrote:

 I think I'm gonna go for serialization and write the serialized object to a
 database in one row of text.
 That's the quick and dirty way of doing things I guess.

 Also, I'm done with Parcelable since I need to pass data back and forth.
 I've already reverted to
 passing a parameter in a global variable: it's the quickest and easiest
 way.


I predict regret =) Good luck.

-
TreKing http://sites.google.com/site/rezmobileapps/treking - Chicago
transit tracking app for Android-powered devices

-- 
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

Re: [android-developers] parcelable again: passing object BACK through activity stack

2011-09-21 Thread Streets Of Boston
1. Try to avoid Serializable. It is very slow compared to Parcelable.
2. Take a look at startActivityForResult and onActivityResult.
3. If you reeeaaally need to update activity A about events from activity B, 
consider putting your own subclass of ResultReceiver in the Intent's 
'extras'. Then activity B can call 'send(...)' on that ResultReceiver and 
this will be received in activity A as an 'onReceiveResult(...)' call-back.

-- 
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

Re: [android-developers] parcelable again: passing object BACK through activity stack

2011-09-21 Thread Richard Schilling
This is some good sound advice.  If you don't want to 
use startActivityForResult and onActivityResult then you can store your data 
in some source of truth like the SQLite database, or even shared 
preferences if you just have a few data items.


Richard 

-- 
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] parcelable again: passing object BACK through activity stack

2011-09-20 Thread John Goche
Hello,

I have two A and B and clicking on a button in A opens B.
I pass an object from A to B using parcelable and the extras in the
intent used to open B. Now I have the following problem: given that
A is beneath B on the activity stack and will not be reopened, how
do I pass the object from B back to activity A?

Thanks for your help,

John Goche

-- 
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

Re: [android-developers] parcelable again: passing object BACK through activity stack

2011-09-20 Thread Mark Murphy
You probably should reconsider your approach. It sounds like you need
a central data model, accessible from multiple activities:

-- database
-- file

managed by:

-- service
-- some other singleton
-- custom Application class

Extras on Intents should be viewed much along the lines of GET
parameters on Web pages. You wouldn't talk about passing a GET
parameter back to some page in the user's history.

On Tue, Sep 20, 2011 at 7:55 AM, John Goche johngoch...@googlemail.com wrote:

 Hello,

 I have two A and B and clicking on a button in A opens B.
 I pass an object from A to B using parcelable and the extras in the
 intent used to open B. Now I have the following problem: given that
 A is beneath B on the activity stack and will not be reopened, how
 do I pass the object from B back to activity A?

 Thanks for your help,

 John Goche

 --
 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



-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

Android Training...At Your Office: http://commonsware.com/training

-- 
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


Re: [android-developers] parcelable again: passing object BACK through activity stack

2011-09-20 Thread TreKing
On Tue, Sep 20, 2011 at 6:55 AM, John Goche johngoch...@googlemail.comwrote:

 given that A is beneath B on the activity stack and will not be reopened


What do you mean A will not be reopened ?

You're probably looking for startActivityForResult() and onActivityResult().

-
TreKing http://sites.google.com/site/rezmobileapps/treking - Chicago
transit tracking app for Android-powered devices

-- 
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

Re: [android-developers] parcelable again: passing object BACK through activity stack

2011-09-20 Thread John Goche
Perhaps I can use the Serializable interface and simply serialize

On Tue, Sep 20, 2011 at 2:33 PM, Mark Murphy mmur...@commonsware.comwrote:

You probably should reconsider your approach. It sounds like you need
 a central data model, accessible from multiple activities:

 -- database
 -- file


 managed by:

 -- service
 -- some other singleton
 -- custom Application class


I think I'm gonna go for serialization and write the serialized object to a
database in one row of text.
That's the quick and dirty way of doing things I guess.

Also, I'm done with Parcelable since I need to pass data back and forth.
I've already reverted to
passing a parameter in a global variable: it's the quickest and easiest way.

Regards,

John Goche

-- 
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