I did a little poking around and I think I can DEFINITELY shine some
light on this.

Basically, I think the difference lies in the way Eclipse ports the
apk to the emulator and launches it.

I just downloaded GeoWebOne from the AdvAndroid site, created an
Eclipse project out of it.  No problems compiling or anything.  I put
in a little Log.i() call in GeoWebOne's onCreate call that reads
"GeoWebOne onCreate".  I then right-clicked (I'm on Windows XP, btw)
the project and selected Run As -> Android Application.  The console
spit this out:

[2009-04-08 17:49:01 - GeoWebOne] ------------------------------
[2009-04-08 17:49:01 - GeoWebOne] Android Launch!
[2009-04-08 17:49:01 - GeoWebOne] adb is running normally.
[2009-04-08 17:49:01 - GeoWebOne] Launching:
com.commonsware.android.geoweb.GeoWebOne
[2009-04-08 17:49:01 - GeoWebOne] Automatic Target Mode: using
existing emulator: emulator-5554
[2009-04-08 17:49:01 - GeoWebOne] Uploading GeoWebOne.apk onto device
'emulator-5554'
[2009-04-08 17:49:01 - GeoWebOne] Installing GeoWebOne.apk...
[2009-04-08 17:49:03 - GeoWebOne] Success!
[2009-04-08 17:49:03 - GeoWebOne] Starting activity
com.commonsware.android.geoweb.GeoWebOne on device
[2009-04-08 17:49:05 - GeoWebOne] ActivityManager: Starting: Intent
{ comp={com.commonsware.android.geoweb/
com.commonsware.android.geoweb.GeoWebOne} }

And then the app launched in the emulator, everything seemed normal,
and in my Logs I got a "GeoWebOne onCreate".

I then hit the Home button on the emulator, went into the applications
launching screen, then re-opened the app (GeoWeb Demo #1), and got
ANOTHER "GeoWebOne onCreate".  I should not have gotten this unless I
hit the Back button before, as opposed to the Home button.
Furthermore, from this point, when I hit the Back button, it shows me
the same activity, which I'm sure has got to be the FIRST instance of
the activity that was created.

I then uninstalled the app from the emulator, and then opened up a
command prompt, and using the adb I manually installed the
GeoWebOne.apk to the emulator.  I then did the same process, opened
the app, hit the home button, went back in, and it behaved as it
should have - I only got ONE "GeoWebOne onCreate" in the logs.

It seems that eclipse ports the app to the emulator in such a way that
each successive launch that is made while the app is running pushes
another instance of the app onto the stack, unless you hit the back
button before relaunching.  Indeed, you can launch the app from
eclipse, and then hit Home and go back into it X number of times, and
after this you will have to press Back X times to actually exit the
app.

I've had this same problem in my other projects, and tried adding
numerous Android Manifest elements to my activities, the one's listed
at http://developer.android.com/guide/topics/manifest/activity-element.html
, to no avail (I thought it was something in the manifest like
android:alwaysRetainTaskState="true", for instance, but it's not).
The difference is eclipse, but I suspect that also first installing
the app on the device from the Market, or AppsInstaller, or
downloading it from the Browser may produce this behavior as well.

Any light that you guys can shine on this would help a lot, and well
done on providing very helpful examples and suggestions, Mark, you've
been quite a legend on this forum!

Thank you!

-Zack

On Mar 29, 7:53 pm, Mark Murphy <[email protected]> wrote:
> j wrote:
> > I launch my TestWebViewactivity.  After my web page is loaded, I put
> > the app in the background by pressing the Home key.  Then I bring the
> > TestWebActivity back to the foreground.  Unexpectedly, TestWebView's
> > onCreate() is called when I bring theactivityto the foreground.  But
> > onDestroy is never called.  This same thing happens every time I
> > tested.  It appears the old TestWebView was not completely killed so
> > there are possibly duplicate web clients running.
>
> Ummmm...I'm not seeing this in one of my WebView test projects.
>
> Visithttp://commonsware.com/AdvAndroid, download the source code, and
> look at WebView/GeoWeb1. I just put a Log.w() call in onCreate() and
> things behaved as expected: I got the onCreate() when I first fired up
> the app, but when I clicked on Home, then clicked on the app again in
> the launcher, my existing instance popped right back up and I did not
> get a second onCreate() call. If I back-arrow out of the app and then
> relaunch it, I do get another onCreate().
>
> Now, I'm not using setWebChromeClient() or a few of your other options,
> so it's conceivable that somehow changes matters. And you didn't post
> your manifest, so there might be something in there that impacts matters.
>
> But I'd start with some other WebView-using code (either mine or an API
> sample or something) and see if it gives you the same behavior. Assuming
> its onCreate() is not being fired multiple times, start tracking down
> the differences between your app and the working code.
>
> If you can narrow down the source of your difficulty, or if I
> misunderstood the pattern you used to cause the problem, let us know!
>
> --
> Mark Murphy (a Commons 
> Guy)http://commonsware.com|http://twitter.com/commonsguy
>
> Android App Developer Books:http://commonsware.com/books.html
--~--~---------~--~----~------------~-------~--~----~
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