[android-developers] Memory Leak problem (about activity background)

2011-12-10 Thread Ken Yang
Hi!! Dear All,

I have an app that contains many Activity. (ex: i got 10 Activity
which be named a1,a2,a3,a10)

and all of the Activity(a1,a2,a3a10) have background like this.
http://schemas.android.com/apk/res/
android"
android:background="@drawable/bg_normal">


and
a1 will redirect to a2,
a2 to a3,
a3 to a4,
.

then..the problem is happened
【OutofMemoryError: bitmap size exceeds VM budget (Android)】

I think the problem is background..
I know how to unbindDrawable or recycle a bitmap,
but how to release the memory after I change activity
【startActivity(aX,aY)】.


I have tried to 【view.getBackground().setCallback(null)】 at onPause().
but the heap is still not released...



Does anyone know how to solve this problem?
or have a better suggestion?











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


[android-developers] Re: Killi Process with files on SD card

2010-08-30 Thread Ken Yang
Hi, Excuse..

I did it the same way...

but it only works on 1.6、2.1 device..

it's doesn't work on 2.2 device, no matter on nexus one or 2.2
emulator...

how can you do that on nexus one?


this is my code


public class serviceSDcard extends Service {

private static Context contextService   = null;
private static AppWidgetManager awmService  = null;
public static boolean bIsUnmount= false;
@Override
public IBinder onBind(Intent intent) {
return null;
}

@Override
public void onStart(Intent intent, int startId) {



IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Intent.ACTION_MEDIA_MOUNTED);
intentFilter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
intentFilter.addDataScheme("file");
intentFilter.addDataAuthority("*", null);

registerReceiver(receiver, intentFilter);
super.onStart(intent, startId);
}
private BroadcastReceiver receiver = new BroadcastReceiver() {

@Override
public void onReceive(Context context, Intent intent) {
try {
bIsUnmount  = !bIsUnmount;

if 
(intent.getAction().equals(Intent.ACTION_MEDIA_UNMOUNTED)){

beauty_large_main.fos.close();


}else{


}


} catch (Exception e) {
Log.d("main", e.toString());
}

}
};
}


On Jul 15, 12:23 am, Streets Of Boston 
wrote:
> It works fine for me on my motorola droid, nexus one and G1.
> Did you properly register your broadcast receiver, both in code and in
> the Android Manifest XML?
>
> On Jul 13, 7:21 pm, ls02  wrote:
>
>
>
> > I tried this on Motorola DROID and it does not work. I do not receive
> > any events in receiver onReceive.
>
> > On Jul 10, 9:23 pm, Streets Of Boston  wrote:
>
> > > Register your broadcast receiver like this:
>
> > > IntentFilter intentFilter = new
> > > IntentFilter(Intent.ACTION_MEDIA_EJECT);
> > > intentFilter.addAction(Intent.ACTION_MEDIA_MOUNTED);
> > > intentFilter.addDataScheme("file");
> > > intentFilter.addDataAuthority("*", null);
> > > intentFilter.addDataPath((mIsExternal
> > >                            ?CursorUtils.EXTERNAL_STORAGE_ROOT
> > >                            
> > > :CursorUtils.PHONE_STORAGE_ROOT).getAbsolutePath(),
> > > PatternMatcher.PATTERN_LITERAL);
> > > context.registerReceiver(this, intentFilter);
>
> > > Then close all your files when you get an ACTION_MEDIA_EJECT
> > > and re-open them (if necessary) on ACTION_MEDIA_MOUNTED.
> > > (in the 'public void onReceive(Context context, Intent intent)' method
> > > of this broadcast receiver).
>
> > > (EXTERNAL_STORAGE_ROOT is the standard value for external-storage
> > > (usually "/sdcard") and PHONE_STORAGE_ROOT is "/emmc" (for HTC
> > > Incredible and such phones)).
>
> > > I'm not sure if this is the 'official' way of doing it, but it works
> > > for me. :)
>
> > > On Jul 10, 3:50 pm, ls02  wrote:
>
> > > > I register for this broadcast. However the process is killed before I
> > > > receive any broadcast event.
>
> > > > On Jul 10, 2:59 pm, Dianne Hackborn  wrote:
>
> > > > > There is a broadcast sent when the SD card is being unmounted (sorry 
> > > > > I don't
> > > > > remember the name off-hand).  You should close all your files at that 
> > > > > point.
> > > > >  If you don't, the platform needs to kill the process because Linux 
> > > > > can't
> > > > > unmount the file system while any files remain open on it.
>
> > > > > On Sat, Jul 10, 2010 at 10:35 AM, ls02  wrote:
> > > > > > I found that Android kills my app process that has files open on SD
> > > > > > card when the card is mounted when the device connects to a 
> > > > > > computer.
> > > > > > It is done without any notification, I see in the log something like
> > > > > > KillProcessWithFilesOpenedOnCard message, my app receives no
> > > > > > notification, has no chance to gracefully shutdown. Moreover Android
> > > > > > restarts my app immediately after killing it with latest Activity 
> > > > > > not
> > > > > > the default activity launched in default standard mode. It does it
> > > > > > while the card is still mounted and device is still connected to a
> > > > > > computer.
>
> > > > > > Can someone explain this all to me, how it I supposed to work, and 
> > > > > > if
> > > > > > there is any way to alter this weird rude behavior? Particularly, if
> > > > > > there is way to get any notification before the process is killed by
> > > > > > the OS and to prevent relaunching it while the card is still 
> > > > > > mounted?
>
> > > > > > --
> > > > > > You received this

[android-developers] Re: Killi Process with files on SD card

2010-08-30 Thread Ken Yang
I find it works on 2.1 and 1.5 device(emualtor), but it doesn't work
on my nexus one(2.2) or 2.2 emulator?  why?

On 7月15日, 上午12時23分, Streets Of Boston  wrote:
> It works fine for me on my motorola droid, nexus one and G1.
> Did you properly register your broadcast receiver, both in code and in
> the Android Manifest XML?
>
> On Jul 13, 7:21 pm, ls02  wrote:
>
>
>
> > I tried this on Motorola DROID and it does not work. I do not receive
> > any events in receiver onReceive.
>
> > On Jul 10, 9:23 pm, Streets Of Boston  wrote:
>
> > > Register your broadcast receiver like this:
>
> > > IntentFilter intentFilter = new
> > > IntentFilter(Intent.ACTION_MEDIA_EJECT);
> > > intentFilter.addAction(Intent.ACTION_MEDIA_MOUNTED);
> > > intentFilter.addDataScheme("file");
> > > intentFilter.addDataAuthority("*", null);
> > > intentFilter.addDataPath((mIsExternal
> > >                            ?CursorUtils.EXTERNAL_STORAGE_ROOT
> > >                            
> > > :CursorUtils.PHONE_STORAGE_ROOT).getAbsolutePath(),
> > > PatternMatcher.PATTERN_LITERAL);
> > > context.registerReceiver(this, intentFilter);
>
> > > Then close all your files when you get an ACTION_MEDIA_EJECT
> > > and re-open them (if necessary) on ACTION_MEDIA_MOUNTED.
> > > (in the 'public void onReceive(Context context, Intent intent)' method
> > > of this broadcast receiver).
>
> > > (EXTERNAL_STORAGE_ROOT is the standard value for external-storage
> > > (usually "/sdcard") and PHONE_STORAGE_ROOT is "/emmc" (for HTC
> > > Incredible and such phones)).
>
> > > I'm not sure if this is the 'official' way of doing it, but it works
> > > for me. :)
>
> > > On Jul 10, 3:50 pm, ls02  wrote:
>
> > > > I register for this broadcast. However the process is killed before I
> > > > receive any broadcast event.
>
> > > > On Jul 10, 2:59 pm, Dianne Hackborn  wrote:
>
> > > > > There is a broadcast sent when the SD card is being unmounted (sorry 
> > > > > I don't
> > > > > remember the name off-hand).  You should close all your files at that 
> > > > > point.
> > > > >  If you don't, the platform needs to kill the process because Linux 
> > > > > can't
> > > > > unmount the file system while any files remain open on it.
>
> > > > > On Sat, Jul 10, 2010 at 10:35 AM, ls02  wrote:
> > > > > > I found that Android kills my app process that has files open on SD
> > > > > > card when the card is mounted when the device connects to a 
> > > > > > computer.
> > > > > > It is done without any notification, I see in the log something like
> > > > > > KillProcessWithFilesOpenedOnCard message, my app receives no
> > > > > > notification, has no chance to gracefully shutdown. Moreover Android
> > > > > > restarts my app immediately after killing it with latest Activity 
> > > > > > not
> > > > > > the default activity launched in default standard mode. It does it
> > > > > > while the card is still mounted and device is still connected to a
> > > > > > computer.
>
> > > > > > Can someone explain this all to me, how it I supposed to work, and 
> > > > > > if
> > > > > > there is any way to alter this weird rude behavior? Particularly, if
> > > > > > there is way to get any notification before the process is killed by
> > > > > > the OS and to prevent relaunching it while the card is still 
> > > > > > mounted?
>
> > > > > > --
> > > > > > 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 > > > > >  ­­cr...@googlegroups.com>
> > > > > > For more options, visit this group at
> > > > > >http://groups.google.com/group/android-developers?hl=en
>
> > > > > --
> > > > > Dianne Hackborn
> > > > > Android framework engineer
> > > > > hack...@android.com
>
> > > > > 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.- Hide quoted text -
>
> > > > - Show quoted text -- Hide quoted text -
>
> > - Show quoted text -

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


[android-developers] I registered a broadcast to detect sd card status, but it only works on the device below 2.1(include 2.1)

2010-08-30 Thread Ken Yang
I registered a broadcast  to detect sd card status, but it only works
on the device below 2.1(include 2.1)

it's doesn't work on nexus one or 2.2 emulator...

android os will kill my process on nexus one and 2.2 emulator, but it
won't do that on device below 2.1(include 2.1)

is there anything wrong?




public class serviceSDcard extends Service {

private static Context contextService   = null;
private static AppWidgetManager awmService  = null;
public static boolean bIsUnmount= false;
@Override
public IBinder onBind(Intent intent) {
return null;
}

@Override
public void onStart(Intent intent, int startId) {

IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Intent.ACTION_MEDIA_MOUNTED);
intentFilter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
intentFilter.addDataScheme("file");
intentFilter.addDataAuthority("*", null);

registerReceiver(receiver, intentFilter);
super.onStart(intent, startId);
}
private BroadcastReceiver receiver = new BroadcastReceiver() {

@Override
public void onReceive(Context context, Intent intent) {
try {
bIsUnmount  = !bIsUnmount;
if 
(intent.getAction().equals(Intent.ACTION_MEDIA_UNMOUNTED)){
beauty_large_main.fos.close();

}else{

}

} catch (Exception e) {
Log.d("main", e.toString());
}

}
};
}

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