Well, something is happening differently in your program flow.  You know
your app better than I.  Look at the output of "adb shell dumpsys activity"
to see the activity stacks that are happening; look at the logcat to see
what the activity manager is doing.  Obviously, singleTask and
singleInstance can have significant impacts on flow through activities as
decribed in the documentation, and this can certainly cause differences in
behavior.  Given that what you are doing is highly questionable from the
start, I'm not sure how much I can really help beyond this.

On Mon, Sep 7, 2009 at 2:00 AM, indra <[email protected]> wrote:

>
> Like you said, the design may be revisited and may be corrected.
> Thanks.
> But how i am getting different results while running it standalone
> (singleTop) and by running it through root activity which is
> (singleInstance)?
> can you throw some light on that? well I really appreciate your help.
>
> On Sep 7, 11:17 am, Dianne Hackborn <[email protected]> wrote:
> > Well it seems pretty broken to me what you are doing, anyway.  For
> example,
> > if the locale changes your activity will be destroyed and recreated for
> the
> > new locale, blowing away your list.  Either make your list a member
> variable
> > of the activity and initialize it in onCreate(), or have it static and
> > really deal with it as a true global (not blowing it away when an
> activity
> > happens to be created); mixing the two models up like that is just going
> to
> > cause problems.
> >
> >
> >
> > On Sun, Sep 6, 2009 at 10:51 PM, indra <[email protected]> wrote:
> >
> > > ok Dianne, then,
> >
> > > Class MySingleton
> > > {
> > > static List<> myList;
> > > }
> >
> > > //This activity is singleTop
> > > Class MyActivity
> > > {
> > > onCreate(Bundle)
> > > {
> > > initStaticList(); //say the init size is 2
> > > }
> >
> > > //Now suppose in between some other activity add 2 more objects in
> > > myList
> > > map()
> > > {
> > > int size = MySingleton.myList.size();
> > > }
> >
> > > }
> >
> > > When I run this scenario using singleTask/singleInstance root
> > > activity, I always get size 2.
> > > But when I run this activity standalone, I get the desired result as
> > > 4.
> > > I am not saying it is because of singleTask or singleTop, but this is
> > > what is happening.
> >
> > > Is there something I am doing wrong here? Please suggest something!
> >
> > > On Sep 6, 11:24 pm, Dianne Hackborn <[email protected]> wrote:
> > > > Sorry I can't understand what you are doing enough to help.  If you
> have
> > > a
> > > > static variable holding a singleton, it will hold whatever the last
> value
> > > > you put into it is (until your process gets killed, and then of
> course
> > > the
> > > > next time it is restarted it will be re-initialized to its default
> > > value).
> > > >  There is nothing about activities or anything else in Android that
> has
> > > an
> > > > impact on this fundamental behavior.
> >
> > > > On Sun, Sep 6, 2009 at 3:48 AM, indra <[email protected]> wrote:
> >
> > > > > Hi,
> > > > > Here I come across a strange problem. I am using a static list (say
> > > > > myList) in a Singleton class, which I use in a activity (say
> > > > > myActivity) which is run by a singleTask root activity
> (rootActivty).
> > > > > But when i try to access myList in the myActivity, I do not get a
> > > > > refreshed version of that myList, instead I get the value one which
> I
> > > > > first time accessed in myActivity.
> > > > > Strangle when I run this myActivity standalone I get correct values
> of
> > > > > myList each time.
> > > > > Please help me out.
> > > > > Thanks and Regards
> > > > > Indra
> >
> > > > > On Aug 25, 9:46 pm, Dianne Hackborn <[email protected]> wrote:
> > > > > > Please read the documentation.  As I said in my original post,
> this
> > > is
> > > > > for
> > > > > > when your activity gets killed while it is in the background.
>  When
> > > you
> > > > > > press back, the default implementation is to finish() the
> activity so
> > > > > there
> > > > > > is no longer any instance data.
> >
> > > > > > On Tue, Aug 25, 2009 at 6:57 AM, sdphil <
> [email protected]>
> > > > > wrote:
> >
> > > > > > > hm...  okay, so I check for null in my onCreate() method.
> >
> > > > > > > public void onCreate(Bundle savedInstanceData) {
> > > > > > >    if (savedInstanceData == null) {
> > > > > > >        // do everything I did before.
> > > > > > >        // show splash screen
> > > > > > >        super.onCreate(savedInstanceState);
> > > > > > >    }
> > > > > > > }
> >
> > > > > > > However, now if I'm in my app, I click on "home", and then
> click on
> > > > > > > the icon again, it behaves as expected, it simply brings the
> app
> > > back
> > > > > > > in the expected state.  If I hit "back" and then click on the
> icon
> > > > > > > again, it behaves like I launched a brand new app - shows the
> > > splash
> > > > > > > screen, etc...
> >
> > > > > > > On Aug 24, 11:24 pm, Dianne Hackborn <[email protected]>
> wrote:
> > > > > > > > The simple fact that it is non-null tells you.  And you can
> have
> > > > > placed
> > > > > > > > anything else you want in there in onSaveInstanceState() for
> > > whatever
> > > > > > > other
> > > > > > > > data you want to retain.  See here:
> >
> > >http://developer.android.com/guide/topics/fundamentals.html#actlife
> >
> > > > > > > > and here:
> >
> > > > > > > >
> http://developer.android.com/reference/android/app/Activity.html
> >
> > > > > > > > On Mon, Aug 24, 2009 at 10:51 PM, sdphil <
> > > [email protected]
> >
> > > > > > > wrote:
> >
> > > > > > > > > "You can use the state passed in to onCreate() to determine
> > > whether
> > > > > > > > > you are starting for the first time or not."
> >
> > > > > > > > > How do I do that?
> >
> > > > > > > > > I'm looking at onCreate --
> >
> > > > > > > > >    public void onCreate(Bundle savedInstanceState) {
> >
> > > > > > > > > and I look at savedInstanceState, nothing jumps out at
> me...
> >
> > > > > > > > > On Aug 24, 10:39 pm, Dianne Hackborn <[email protected]>
> > > wrote:
> > > > > > > > > > If you just want pressing back to not close the activity,
> > > just
> > > > > catch
> > > > > > > the
> > > > > > > > > > BACK key and call Activity.moveTaskToBack() instead of
> > > letting it
> > > > > do
> > > > > > > the
> > > > > > > > > > default behavior (of calling finish()).
> >
> > > > > > > > > > There is no need to use launchMode nor
> alwaysRetainTaskState.
> >
> > > > > > > > > > However, you DO need to deal with the normal lifecycle
> > > behavior
> > > > > -- in
> > > > > > > > > > particular, when you are in the background, regardless of
> how
> > > > > this
> > > > > > > > > happened,
> > > > > > > > > > the system is free to kill your process, so when the user
> > > next
> > > > > > > returns to
> > > > > > > > > > your app a new instance of your activity will be created.
> > >  You
> > > > > can
> > > > > > > use
> > > > > > > > > the
> > > > > > > > > > state passed in to onCreate() to determine whether you
> are
> > > > > starting
> > > > > > > for
> > > > > > > > > the
> > > > > > > > > > first time or not.
> >
> > > > > > > > > > Also, a "quit" menu on an android application is not
> normal,
> > > > > > > expected,
> > > > > > > > > nor
> > > > > > > > > > desired.  Please don't do it; there is no need.  I think
> you
> > > will
> > > > > > > have a
> > > > > > > > > > much better time if you try to design your app to follow
> the
> > > kind
> > > > > of
> > > > > > > flow
> > > > > > > > > > shown by the existing applications, rather than trying to
> > > make it
> > > > > > > work
> > > > > > > > > like
> > > > > > > > > > a desktop application.
> >
> > > > > > > > > > For example: you could save your current state to
> persistent
> > > > > storage
> > > > > > > when
> > > > > > > > > > the user leaves the app, and restore it when they return,
> so
> > > they
> > > > > > > know
> > > > > > > > > they
> > > > > > > > > > will always come back to the same thing.  If it makes for
> > > them to
> > > > > > > > > actually
> > > > > > > > > > throw away that state, you could have an option for them
> to
> > > reset
> > > > > the
> > > > > > > app
> > > > > > > > > so
> > > > > > > > > > they can decide to do that at the time they want, rather
> than
> > > > > having
> > > > > > > to
> > > > > > > > > > decide earlier on to have this happen as a side-effect of
> > > some
> > > > > > > unusual
> > > > > > > > > > "quit" command.
> >
> > > > > > > > > > On Mon, Aug 24, 2009 at 10:16 PM, sdphil <
> > > > > [email protected]
> >
> > > > > > > > > wrote:
> >
> > > > > > > > > > > I want my application to work like this:
> >
> > > > > > > > > > > 1. When the user launches the application, it starts
> up.
> > > > > > > > > > > 2. When the user hits back, or home, the application is
> > > still
> > > > > > > running
> > > > > > > > > > > (although not visible).
> > > > > > > > > > > 3. If the user hits "menu->quit" the application exits
> > > cleanly.
> > > > > > > > > > > 4. If the user starts the application, hits "home" and
> > > selects
> > > > > the
> > > > > > > > > > > application icon *again*, I want it to bring up the
> > > existing
> > > > > > > insance
> > > > > > > > > > > of the application with whatever activity state it had
> > > before
> > > > > it
> > > > > > > left.
> > > > > > > > > > > 5. I do not ever want more than one instance of my
> > > application
> > > > > to
> > > > > > > be
> > > > > > > > > > > running (i.e. singleton).
> > > > > > > > > > > 6. I always want to retain activity stack/state.  when
> you
> > > come
> > > > > > > back
> > > > > > > > > > > into the application, it's like you never left.
> >
> > > > > > > > > > > <?xml version="1.0" encoding="utf-8"?>
> > > > > > > > > > > <manifest xmlns:android="
> > > > > > >http://schemas.android.com/apk/res/android";
> > > > > > > > > > >          package="com.company.gui"
> > > > > > > > > > >          android:versionCode="1"
> > > > > > > > > > >          android:versionName="1.0">
> > > > > > > > > > >    <application android:icon="@drawable/icon"
> > > > > > > > > > >                 android:label="@string/app_name"
> > > > > > > > > > >                 android:debuggable="true">
> > > > > > > > > > >        <activity android:name=".Main"
> > > > > > > > > > >                  android:launchMode="singleTask"
> > > > > > > > > > >                  android:alwaysRetainTaskState="true"
> > > > > > > > > > >                  android:label="@string/app_name"
> > > > > > > > > > >                  android:screenOrientation="portrait"
> >
> > > > >  android:theme="@android:style/Theme.NoTitleBar">
> > > > > > > > > > >            <intent-filter>
> > > > > > > > > > >                <action
> > > > > android:name="android.intent.action.MAIN" />
> > > > > > > > > > >                <category
> > > > > > > > > > > android:name="android.intent.category.LAUNCHER" />
> > > > > > > > > > >            </intent-filter>
> > > > > > > > > > >        </activity>
> >
> > > > > > > > > > >        <activity android:name=".SplashScreen"
> > > > > > > > > > >                  android:label="@string/app_name">
> > > > > > > > > > >        </activity>
> >
> > > > > > > > > > >    </application>
> > > > > > > > > > >    <uses-sdk android:minSdkVersion="3" />
> > > > > > > > > > > <uses-permission
> > > > > android:name="android.permission.INTERNET"></uses-
> > > > > > > > > > > permission>
> > > > > > > > > > > </manifest>
> >
> > > > > > > > > > > my main activity onCreate() looks like this:
> >
> > > > > > > > > > >        startActivityForResult( new Intent(this,
> > > > > > > SplashScreen.class),
> >
> > ...
> >
> > read more ยป- Hide quoted text -
> >
> > - Show quoted text -
> >
>


-- 
Dianne Hackborn
Android framework engineer
[email protected]

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

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