Re: [android-developers] capturing Home key event at application level

2011-02-15 Thread kavitha b
No,Manish

It is not possible to capture HomeKeyPress.

But there must be possibility to check whether ur app is in foreground.


On Tue, Feb 15, 2011 at 4:20 PM, cool.manish mannishga...@gmail.com wrote:

 Hi,

 How can we capture home key event?
 I am storing some data at application level, I want to clear it so
 that it doesn't consume memory when my application is in background.
 At the same time, i wish that this data shouldn't get earsed if my
 application has gone in the background because of an incoming call.

 Do I need to capture key event in every activity? Is it possible to
 handle it at application level, so that i dont have to handle it in
 every activity and rewrite the same code.

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

-- 
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] capturing Home key event at application level

2011-02-15 Thread Marcin Orlowski
 I am storing some data at application level, I want to clear it so
 that it doesn't consume memory when my application is in background.
 At the same time, i wish that this data shouldn't get earsed if my
 application has gone in the background because of an incoming call.

 Do I need to capture key event in every activity? Is it possible to
 handle it at application level, so that i dont have to handle it in
 every activity and rewrite the same code.

I'd suggest you read on Activity life cycle and write your resource saving
code in the right methods, so you get your goal without dirtry trickery.
http://developer.android.com/reference/android/app/Activity.html

-- 
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] capturing Home key event at application level

2011-02-15 Thread Kostya Vasilyev

15.02.2011 13:50, cool.manish пишет:

I am storing some data at application level, I want to clear it so
that it doesn't consume memory when my application is in background.


From what I can find in the documentation, it's not clear if this can 
reduce memory consumption.


An application sitting in the background is presumably not running any 
code and not making allocations, so there is nothing to trigger garbage 
collection (and cause the heap allocated by Dalvik VM from the Linux 
kernel to shrink).


Later, if Android runs out of global memory, it's documented that it 
just starts killing background processes in their entirety. It's not 
documented that there is any attempt to run garbage collection on 
background applications' heaps and shrink them to free up global memory.


Perhaps this (garbage collection on background applications) actually 
does happen but just isn't documented, then freeing memory before going 
into the background is a useful thing.


Can this be clarified?

--
Kostya Vasilyev -- http://kmansoft.wordpress.com


--
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] capturing Home key event at application level

2011-02-15 Thread Jonas Petersson

2011-02-15 12:21, Kostya Vasilyev skrev:

[...]
Perhaps this (garbage collection on background applications) actually
does happen but just isn't documented, then freeing memory before going
into the background is a useful thing.


Well, I have not double checked for a while now, but the onLowMemory() 
method of my service was certainly called now and then (even though my 
service wasn't doing anything at all at the time) last I traced it. Does 
this qualify?


Best / Jonas

--
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] capturing Home key event at application level

2011-02-15 Thread Kostya Vasilyev

15.02.2011 14:41, Jonas Petersson пишет:




Well, I have not double checked for a while now, but the onLowMemory() 
method of my service was certainly called now and then (even though my 
service wasn't doing anything at all at the time) last I traced it. 
Does this qualify?


Best / Jonas 


It does qualify, but to a point:

http://developer.android.com/reference/android/content/ComponentCallbacks.html#onLowMemory()
This is called when the overall system is running low on memory, and 
would like actively running process to try to tighten their belt. 
While the exact point at which this will be called is not defined, 
generally it will happen around the time all background process have 
been killed, that is before reaching the point of killing processes 
hosting service and foreground UI that we would like to avoid killing.


Note that it says actively running process, all background process 
have been killed, and before reaching the point of killing processes 
hosting service and foreground UI - which I'm reading to mean that this 
applies to foreground-class processes.


The original question was, are *background* process heaps ever GC'd and 
shrunk?


Was your service bound to a visible activity, previously called 
startForeground, or running locally within a foreground process?


--
Kostya Vasilyev -- http://kmansoft.wordpress.com

--
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] capturing Home key event at application level

2011-02-15 Thread Jonas Petersson

2011-02-15 12:58, Kostya Vasilyev skrev:

15.02.2011 14:41, Jonas Petersson пишет:

Well, I have not double checked for a while now, but the onLowMemory()
method of my service was certainly called now and then (even though my
service wasn't doing anything at all at the time) last I traced it.
Does this qualify?


It does qualify, but to a point:

http://developer.android.com/reference/android/content/ComponentCallbacks.html#onLowMemory()

This is called when the overall system is running low on memory, and
would like actively running process to try to tighten their belt.
While the exact point at which this will be called is not defined,
generally it will happen around the time all background process have
been killed, that is before reaching the point of killing processes
hosting service and foreground UI that we would like to avoid killing.


Note that it says actively running process, all background process
have been killed, and before reaching the point of killing processes
hosting service and foreground UI - which I'm reading to mean that this
applies to foreground-class processes.

The original question was, are *background* process heaps ever GC'd and
shrunk?

Was your service bound to a visible activity, previously called
startForeground, or running locally within a foreground process?


This was a while ago (1.1/1.5 IIRC) so there was no startForeground, but 
I'm pretty sure I used setForeground(true) to be less likely to get 
killed. It was completely invisible as all it did was the classic: look 
for unknown incoming phone numbers an look them up from web service 
(plus store in the phonebook). The gui was just a Toast. (Yes, I'm aware 
that there are ways to do this without a service - this was just 
something I did to play around with the system.)


Best / Jonas

--
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] capturing Home key event at application level

2011-02-15 Thread Kostya Vasilyev

15.02.2011 15:18, Jonas Petersson пишет:


This was a while ago (1.1/1.5 IIRC) so there was no startForeground, 
but I'm pretty sure I used setForeground(true) to be less likely to 
get killed.


Ok, thanks for clarifying.

--
Kostya Vasilyev -- http://kmansoft.wordpress.com


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