[android-developers] Re: Lifetime of static [instance] variables

2011-05-29 Thread Anirban Majumdar
i just recalled i wanted one last thing clarified -

in an android system, what's the relevance of the "Task Manager"? i was
under the impression that if i were to terminate an application there, it
also meant that its related process would end. Conversely, i believed that
if the process related to an app is running, then it shows up in the Task
Manager.

Clearly this is not the case, as i verified on my device. So can you let me
know what precisely is the role of the Task Manager?

On Sun, May 29, 2011 at 4:53 PM, Anirban Majumdar <
anirvan.majum...@gmail.com> wrote:

> I am so thankful to you kostya, for such an excellent and simple
> explanation.
>
> Lesson learnt. Thanks again.
> On 29 May 2011 15:13, "Kostya Vasilyev"  wrote:
> > Replying back to the list.
> >
> > Most (all?) platforms' model is process == application (more or less).
> >
> > In Android, there really is no such thing as "the application" (there is,
> > but it is useful to ignore it at first). Therefore, one should unlearn
> that
> > equality between "application" and process
> >
> > The unit of installation is package, and the unit of execution is
> component.
> > Components come in various shapes: activity, broadcast receiver, service,
> > content provider, etc. These components have well defined lifecycles with
> > callbacks.
> >
> > On the other hand, a process is more or less just an implementation
> detail,
> > having to do more with memory and file protection, crash handling,
> dealing
> > with out of memory situations, etc.
> >
> > Android keeps processes running as long as possible while there is
> > enough memory. This significantly improves performance if the user or the
> > system again needs one of the components provided by this process. Well
> > written code detects when it's in the background and stops CPU intensive
> > work, so it just sits there dormant, not consuming the CPU & battery
> > resources.
> >
> > Mark Murphy compares this model to a web application: just because the
> user
> > left a page, doesn't mean the web server is stopped right away.
> >
> > I see a similarity to Microsoft COM. Android components are similar to
> COM
> > objects with a well defined interface (Automation?). Releasing a COM
> object
> > is not the same as stopping its process, one could keep the process
> around
> > for a while in case another of its objects is needed (although I don't
> > remember is Windows actually does that).
> >
> > There is a hack an application can use to stop its process, but it is
> seen
> > by Android as an application crash, and may have unplesant side effects,
> so
> > I'm not going to provide it here.
> >
> > Bottom line - don't worry about process lifetimes too much yourself, and
> > tell users who do that they need to "learn to stop worrying and love the
> > Android way of managing resources".
> >
> > -- Kostya
> >
> > 2011/5/29 Anirvan 
> >
> >> thanks for your patience and responses kostya. i really appreciate it.
> >>
> >> the tip for tracking the process state through the ddms is a good one.
> >> so far, i've only used the ddms to track memory usage, cpu load and
> >> log comments. and yes, you're right. even upon pressing 'back' from
> >> the one and only main activity does NOT kill the process.
> >>
> >> i wonder why :[ - it feels very counter-intuitive. i understand that
> >> pressing the 'home' button while the app runs, puts the app's state
> >> into a stack which android can recover again. but i certainly feel
> >> that pressing back from the main activity should kill the process
> >> unless explicitly programmed not to do so.
> >>
> >> at this point, i'll need to work around this new found knowledge about
> >> process lifecycles.
> >>
> >> while you mentioned that there doesn't exist a callback mechanism for
> >> process kills, but is there a way through which the app process can be
> >> killed programmatically from within an app?
> >>
> >>
> >> On May 29, 2:14 am, Kostya Vasilyev  wrote:
> >> > Your application logic should be coded in such a way that the process
> can
> >> be
> >> > killed at any time (usually once it's in the background), or not be
> >> killed,
> >> > and still work correctly. There is no callback when the process is
> >> killed.
> >>

[android-developers] Re: Lifetime of static [instance] variables

2011-05-29 Thread Anirban Majumdar
I am so thankful to you kostya, for such an excellent and simple
explanation.

Lesson learnt. Thanks again.
On 29 May 2011 15:13, "Kostya Vasilyev"  wrote:
> Replying back to the list.
>
> Most (all?) platforms' model is process == application (more or less).
>
> In Android, there really is no such thing as "the application" (there is,
> but it is useful to ignore it at first). Therefore, one should unlearn
that
> equality between "application" and process
>
> The unit of installation is package, and the unit of execution is
component.
> Components come in various shapes: activity, broadcast receiver, service,
> content provider, etc. These components have well defined lifecycles with
> callbacks.
>
> On the other hand, a process is more or less just an implementation
detail,
> having to do more with memory and file protection, crash handling, dealing
> with out of memory situations, etc.
>
> Android keeps processes running as long as possible while there is
> enough memory. This significantly improves performance if the user or the
> system again needs one of the components provided by this process. Well
> written code detects when it's in the background and stops CPU intensive
> work, so it just sits there dormant, not consuming the CPU & battery
> resources.
>
> Mark Murphy compares this model to a web application: just because the
user
> left a page, doesn't mean the web server is stopped right away.
>
> I see a similarity to Microsoft COM. Android components are similar to COM
> objects with a well defined interface (Automation?). Releasing a COM
object
> is not the same as stopping its process, one could keep the process around
> for a while in case another of its objects is needed (although I don't
> remember is Windows actually does that).
>
> There is a hack an application can use to stop its process, but it is seen
> by Android as an application crash, and may have unplesant side effects,
so
> I'm not going to provide it here.
>
> Bottom line - don't worry about process lifetimes too much yourself, and
> tell users who do that they need to "learn to stop worrying and love the
> Android way of managing resources".
>
> -- Kostya
>
> 2011/5/29 Anirvan 
>
>> thanks for your patience and responses kostya. i really appreciate it.
>>
>> the tip for tracking the process state through the ddms is a good one.
>> so far, i've only used the ddms to track memory usage, cpu load and
>> log comments. and yes, you're right. even upon pressing 'back' from
>> the one and only main activity does NOT kill the process.
>>
>> i wonder why :[ - it feels very counter-intuitive. i understand that
>> pressing the 'home' button while the app runs, puts the app's state
>> into a stack which android can recover again. but i certainly feel
>> that pressing back from the main activity should kill the process
>> unless explicitly programmed not to do so.
>>
>> at this point, i'll need to work around this new found knowledge about
>> process lifecycles.
>>
>> while you mentioned that there doesn't exist a callback mechanism for
>> process kills, but is there a way through which the app process can be
>> killed programmatically from within an app?
>>
>>
>> On May 29, 2:14 am, Kostya Vasilyev  wrote:
>> > Your application logic should be coded in such a way that the process
can
>> be
>> > killed at any time (usually once it's in the background), or not be
>> killed,
>> > and still work correctly. There is no callback when the process is
>> killed.
>> >
>> > Pressing the back key always finishes the current activity - the back
key
>> > tells Android that the user is done with whatever he was doing in that
>> > activity, and will not come back. But this does not kill the process,
>> > because activity != process.
>> >
>> > Try pressing the home key instead - the activity will be paused /
>> stopped,
>> > but not terminated, then come back by long-pressing the home key - you
>> > should see onStart / onResume, but not onCreate.
>> >
>> > All of this is explained very well here:
>> >
>> > http://developer.android.com/guide/topics/fundamentals/activities.htm.
..
>> >
>> > http://developer.android.com/guide/topics/fundamentals/processes-and-.
..
>> >
>> > For debugging purposes, use "adb shell ps" (the usual Unix "ps" -
process
>> > state), look for your application within the process list, and note its
>> > process ID.
>> >
>> > Or use the DDMS perspective in Eclipse - the second column in the
Devices
>> > panel, under Online, is also the process ID.
>> >
>> > -- Kostya
>> > 2011/5/29 Anirvan 
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> > > thanks for the response Kostya. but i does one truly determine that
>> > > the application 'process' has terminated?
>> >
>> > > for testing, i've created a single Activity which serves as the Main.
>> > > when i press the back button after launching this activity, the app
>> > > ends. i've also verified that the app is no longer running by
checking
>> > > the Task Manager.
>> >
>> > > is there some o