May be your mobile memory is not enough,This problem isn't actually about Phonegap. It's a common issue on native android apps too.It occurs because when the camera is triggered, the android activity goes background (onStop state), waiting for the camera to take the picture. Then the GC comes and kills the activity to free memory before the conclusion of camera action, and when the camera is done your activity has already died. That is why the app is restarted.
Here is my suggests
1 .Replace cramer plugin, avoid using custom plug-ins start garbage collection, (http://code.google.com/p/foreground-camera-plugin/, http://code.google.com/p/foreground-gallery- plugin /)
2. Detects memory if insufficient to kill other processes, active release memory
3. Improve their survival, try to avoid the release of memory in the system selected.
private void clearMemory(boolean killAll)
{
mklog("当前系统可用内存大小是:" + getAvailMemory(getApplicationContext()));
ActivityManager activityManger = (ActivityManager) this
.getSystemService(ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> list = activityManger
.getRunningAppProcesses();
if (list != null)
for (int i = 0; i < list.size(); i++)
{
ActivityManager.RunningAppProcessInfo apinfo = list.get(i);
System.out.println("pid " + apinfo.pid);
System.out.println("processName "
+ apinfo.processName);
System.out
.println("importance " + apinfo.importance);
String[] pkgList = apinfo.pkgList;
if (apinfo.importance >= ActivityManager.RunningAppProcessInfo.IMPORTANCE_BACKGROUND
|| (killAll && apinfo.importance >= ActivityManager.RunningAppProcessInfo.IMPORTANCE_SERVICE))
{
// Process.killProcess(apinfo.pid);
for (int j = 0; j < pkgList.length; j++)
{
activityManger.killBackgroundProcesses(pkgList[j]);
mklog("准备杀死进程:" + pkgList[j]);
}
}
}
mklog("清理之后 当前系统可用内存大小是:" + getAvailMemory(getApplicationContext()));
}
private long getAvailMemory(Context context)
{
ActivityManager am = (ActivityManager) context
.getSystemService(Context.ACTIVITY_SERVICE);
MemoryInfo mi = new MemoryInfo();
am.getMemoryInfo(mi);
return mi.availMem / (1024 * 1024);
}
public void mklog(String contentString)
{
Log.i("Web Console", contentString);
}