Webview Question: onCreate always get called when activity comes to foreground

by UBZack » Thu, 09 Apr 2009 06:10:04 GMT


Sponsored Links
  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 M



Webview Question: onCreate always get called when activity comes to foreground

by Mark Murphy » Thu, 09 Apr 2009 06:44:17 GMT


 


<lengthy detailed analysis snipped>


I don't use Eclipse. If I understand correctly, from this post and
others, is that when you run the application from Eclipse, you are taken
right to the initial activity of that application, bypassing the home
screen and launcher.

In that case, what may be happening is that Eclipse tells the emulator
to launch the root activity...and specifies FLAG_ACTIVITY_NEW_TASK and
 FLAG_ACTIVITY_MULTIPLE_TASK on the launching Intent. That would provide
the behavior you're experiencing, if I understand correctly.


Clearly, Eclipse is part of a broader Hulu-led initiative to "turn our
chunky brain matter into creamy goo". ;-)


Legend? I hope not. Legends are frequently rather dead.

But, thanks!

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

Android App Developer Training:  http://commonsware.com/training.html 

--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Webview Question: onCreate always get called when activity comes to foreground

by UBZack » Fri, 10 Apr 2009 01:20:16 GMT


 Hi Mark, thank you very much for your reply.

I have some more findings to report!  Turns out it's not just
launching it from Eclipse that causes this behavior, but also
downloading the apk from the Android web browser, installing it, and
tapping the launch button.

I set up a basic hello world app, uploaded it to my site, downloaded
it on my G1, installed it, hit the Launch button after it said the
install was successful, and it opened the app, showing the root
activity.  I then hit the Home button, and re-opened the app.  It
opened and showed the root activity, but then I hit the back button,
and it showed the same root activity that was previously instantiated
when it first launched.

I have not tried this with downloading an app from the Android Market,
but I would say that this is a bug in Android that should be fixed,
specifically in its package installer, or perhaps just in launching an
app in general right after installing it.  Anyway, thank you again for
your contributions, and if you have anything else to add to my
observations I'd be more than glad to hear it!

Best,
Zack







--~--~---------~--~----~------------~-------~--~----~



Webview Question: onCreate always get called when activity comes to foreground

by Brian » Tue, 28 Apr 2009 20:17:40 GMT


 ow reading this first would have saved me a many, many hours.

It's not just WebView apps, but can be as simple as Hello,World. I
had a pretty complex app with intents in a tabhost that I thought was
the problem, whittled down to a simple tabhost app with Intents, down
to a tabhost with a view factory, whittled down to just hello world.

What I found was my app launch from eclipse would get onCreate, and
the usual flow. Hitting the home key, then relaunching the app from
the android emulator launcher, would result in another onCreate call.
Repeat this pattern (home key, launch app), and when you get tired,
start hitting the back button in your app.
The prior app instances are shown instead of the launcher.
Until -- your app gets an onDelete(). Now it's ok. Now when you tap
the icon from the launcher (onCreate), hit home, and hit the app icon
again, another onCreate is not sent -- it's working as normal --
hitting back button gets you to the launcher
launcher, and all is good.

Here's all you need to repro the problem: this code, eclipse, and the
plugin.
Build from eclipse, run it from eclipse, app launches. Hit home, hit
the app icon, hit home, hit app icon. Now hit the back button.
- expected is that you would exit back to the launcher
- what you get is a prior instance (I guess) of your app

public class MyTest extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_content);
System.out.println("onCreate");
}



On Apr 9, 1:20pm, UBZack <zferv...@gmail.com> wrote:
--~--~---------~--~----~------------~-------~--~----~



Webview Question: onCreate always get called when activity comes to foreground

by Brian » Tue, 28 Apr 2009 20:53:54 GMT


 A quick workaround for this in Eclipse, is to set your application's
Run Configuration's Launch Action to "Do Nothing".  Now when you press
the play icon to launch, it seems to just push the apk to the emulator
and not launch it.
Then you go in and click your app icon, and launch/relaunch behavior
is as expected.

--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. How to set spinner selection by id not position

I have created a simple Spinner binding it to a SimpleCursorAdapter.
I'm populating the SimpleCursorAdapter with a list of towns from a
content provider.


When I go to save the users selection I'm planning on saving the row id
that is being populated into my SimpleCursorAdapter.


I'm using the following code to get the ID.


townSpinner.getSelectedItemId();



What I can not figure out is how best to set the selection when I pull
back up the saved item.


The following code works but it only sets selection by position number.


townSpinner.setSelection(2);



Should I just create a loop to determine the correct position value
based on Id?



long cityId = Long.parseLong(cursor.getString(CityQuery.CITY_ID));


for (int i = 0; i < citySpinner.getCount(); i++) {
long itemIdAtPosition2 = citySpinner.getItemIdAtPosition(i);
if (itemIdAtPosition2 == cityId) {
citySpinner.setSelection(i);
break;
}

}







Thanks


Zach

-- 

2. Make an app NOT be full screen

I want my app to not obliterate all other apps on the screen and
perhaps to dim them or blur them while keeping just a small panel open
at the bottom.

I've tried this to no avail...

        setContentView(R.layout.main);

 
getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
        getWindow().addFlags(
                WindowManager.LayoutParams.FLAG_DIM_BEHIND |
WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);

Is there a way to do this?

tone

-- 

3. [ANN] Gamine 0.3 (3D game engine)

4. ADB drivers for Windows XP available for Android devices

5. What to use instead of a very long ListPreference?

6. Automatic debuggable in the manifest

7. Combining an image