我想创建一个在图库中查找新图像的服务。当用户有30张新照片时,我想显示提醒信息。
为此,我创建了一个内容解析器并设置了一个ContentObserver,但是当我启动相机并拍摄一些图像时,服务崩溃了,我得到以下异常:
08-03 14:36:22.426 22835-22835/foto.studio W/libc? pthread_create failed: couldn't allocate 1040384-byte stack: Out of memory
08-03 14:36:22.426 22835-22835/foto.studio E/dalvikvm? pthread_create (stack size 16384 bytes) failed: Try again
08-03 14:36:22.426 22835-22835/foto.studio D/AndroidRuntime? Shutting down VM
08-03 14:36:22.426 22835-22835/foto.studio W/dalvikvm? threadid=1: thread exiting with uncaught exception (group=0x41c38c08)
08-03 14:36:22.441 22835-22835/foto.studio I/System.out? Uploading Crash Report!
08-03 14:36:22.446 22835-22835/foto.studio W/libc? pthread_create failed: couldn't allocate 1040384-byte stack: Out of memory
08-03 14:36:22.446 22835-22835/foto.studio E/dalvikvm? pthread_create (stack size 16384 bytes) failed: Try again
可能有什么不对?谢谢!
服务:
public class PrintReminderService extends Service {
SharedPreferences preferences;
private SharedPreferences.Editor editor;
boolean countRegistered = false;
private int countImgesPref;
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
preferences = getSharedPreferences("printReminder", Context.MODE_PRIVATE);
editor = getSharedPreferences("printReminder", Context.MODE_PRIVATE).edit();
final String[] columns = {MediaStore.Images.Media._ID};
final Cursor imagecursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, columns,
null, null, null);
countRegistered = preferences.getBoolean("countRegisteredPref", false);
countImgesPref = preferences.getInt("countImgesPref", 0);
imagecursor.registerContentObserver(new ContentObserver(null) {
@Override
public void onChange(boolean selfChange) {
if(!countRegistered) {
editor = preferences.edit();
editor.putBoolean("countRegisteredPref", true);
editor.putInt("countImgesPref", imagecursor.getCount());
editor.commit();
Log.w("", "countRegisteredPref" + ", saved count is:" + imagecursor.getCount());
}
if(imagecursor.getCount() == (countImgesPref + 4)) {
editor = preferences.edit();
editor.putInt("countImgesPref", imagecursor.getCount());
editor.commit();
Log.w("", "num of images before: " + countImgesPref + " num of images now: " + imagecursor.getCount());
}
}
@Override
public boolean deliverSelfNotifications() {
return true;
}
});
return Service.START_STICKY;
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
}
完成堆栈跟踪:
08-03 14:59:00.471 3623-3623/? I/SELinux﹕ Function: selinux_android_load_priority [0], There is no sepolicy file.
08-03 14:59:00.471 3623-3623/? I/SELinux﹕ Function: selinux_android_load_priority [1], There is no sepolicy version file.
08-03 14:59:00.471 3623-3623/? I/SELinux﹕ Function: selinux_android_load_priority , priority version is VE=SEPF_GT-N7100_4.4.2_0019
08-03 14:59:00.471 3623-3623/? I/SELinux﹕ selinux_android_seapp_context_reload: seapp_contexts file is loaded from /seapp_contexts
08-03 14:59:00.476 3623-3623/? D/dalvikvm﹕ Late-enabling CheckJNI
08-03 14:59:00.646 3623-3623/foto.studio I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations
08-03 14:59:00.646 3623-3623/foto.studio W/dalvikvm﹕ VFY: unable to resolve virtual method 669: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
08-03 14:59:00.646 3623-3623/foto.studio D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
08-03 14:59:00.646 3623-3623/foto.studio I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType
08-03 14:59:00.646 3623-3623/foto.studio W/dalvikvm﹕ VFY: unable to resolve virtual method 691: Landroid/content/res/TypedArray;.getType (I)I
08-03 14:59:00.646 3623-3623/foto.studio D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
08-03 14:59:00.676 3623-3623/foto.studio D/AbsListView﹕ Get MotionRecognitionManager
08-03 14:59:00.761 3623-3623/foto.studio E/libEGL﹕ call to OpenGL ES API with no current context (logged once per thread)
08-03 14:59:00.776 3623-3623/foto.studio I/dalvikvm﹕ Could not find method android.app.Notification$Builder.setLocalOnly, referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zza
08-03 14:59:00.776 3623-3623/foto.studio W/dalvikvm﹕ VFY: unable to resolve virtual method 275: Landroid/app/Notification$Builder;.setLocalOnly (Z)Landroid/app/Notification$Builder;
08-03 14:59:00.776 3623-3623/foto.studio D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x00c2
08-03 14:59:00.776 3623-3623/foto.studio I/dalvikvm﹕ Could not find method android.content.pm.PackageManager.getPackageInstaller, referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zzh
08-03 14:59:00.776 3623-3623/foto.studio W/dalvikvm﹕ VFY: unable to resolve virtual method 591: Landroid/content/pm/PackageManager;.getPackageInstaller ()Landroid/content/pm/PackageInstaller;
08-03 14:59:00.776 3623-3623/foto.studio D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x000b
08-03 14:59:00.781 3623-3623/foto.studio I/gcm﹕ Registration not found
08-03 14:59:00.781 3623-3623/foto.studio I/gcm﹕ registration starterd!
08-03 14:59:00.781 3623-3646/foto.studio W/InstanceID/Rpc﹕ Found 10042
08-03 14:59:00.796 3623-3645/foto.studio E/ImageLoader﹕ Unable to resolve host "graph.facebook.com": No address associated with hostname
08-03 14:59:00.851 3623-3623/foto.studio I/dalvikvm-heap﹕ Grow heap (frag case) to 12.663MB for 1065616-byte allocation
08-03 14:59:00.886 3623-3623/foto.studio W/ImageLoader﹕ Try to initialize ImageLoader which had already been initialized before. To re-init ImageLoader with new configuration call ImageLoader.destroy() at first.
08-03 14:59:00.916 3623-3623/foto.studio I/LOGTAG﹕ Table has been created!
08-03 14:59:00.926 3623-3623/foto.studio I/TAG﹕ Datasource opened!
08-03 14:59:01.051 3623-3623/foto.studio W/﹕ countRegisteredPref: false curent images: 100 and saved images: 0
08-03 14:59:01.161 3623-3623/foto.studio E/ViewSystem﹕ ViewRootImpl #2 Surface is not valid.
08-03 14:59:01.176 3623-3623/foto.studio I/dalvikvm-heap﹕ Grow heap (frag case) to 16.618MB for 2151616-byte allocation
08-03 14:59:01.241 3623-3623/foto.studio I/version﹕ old version 36 new version 36
08-03 14:59:01.276 3623-3657/foto.studio D/GraphRequest﹕ Warning: Request without access token missing application ID or client token.
08-03 14:59:01.311 3623-3623/foto.studio D/libEGL﹕ loaded /system/lib/egl/libEGL_mali.so
08-03 14:59:01.311 3623-3623/foto.studio D/libEGL﹕ loaded /system/lib/egl/libGLESv1_CM_mali.so
08-03 14:59:01.316 3623-3623/foto.studio D/libEGL﹕ loaded /system/lib/egl/libGLESv2_mali.so
08-03 14:59:01.321 3623-3623/foto.studio E/﹕ Device driver API match
Device driver API version: 29
User space API version: 29
08-03 14:59:01.321 3623-3623/foto.studio E/﹕ mali: REVISION=Linux-r3p2-01rel3 BUILD_DATE=Tue Jul 22 19:59:34 KST 2014
08-03 14:59:01.381 3623-3623/foto.studio D/OpenGLRenderer﹕ Enabling debug mode 0
08-03 14:59:01.601 3623-3664/foto.studio D/dalvikvm﹕ GC_FOR_ALLOC freed 2951K, 23% free 15139K/19556K, paused 22ms, total 22ms
08-03 14:59:01.621 3623-3633/foto.studio W/CursorWrapperInner﹕ Cursor finalized without prior close()
08-03 14:59:02.396 3623-3623/foto.studio D/dalvikvm﹕ GC_FOR_ALLOC freed 1981K, 20% free 15669K/19556K, paused 62ms, total 63ms
08-03 14:59:03.516 3623-3623/foto.studio D/dalvikvm﹕ GC_FOR_ALLOC freed 2447K, 20% free 15912K/19816K, paused 52ms, total 52ms
08-03 14:59:04.831 3623-3623/foto.studio D/dalvikvm﹕ GC_FOR_ALLOC freed 2557K, 20% free 16125K/20140K, paused 69ms, total 69ms
08-03 14:59:06.236 3623-5354/foto.studio D/dalvikvm﹕ GC_FOR_ALLOC freed 2623K, 20% free 16344K/20424K, paused 42ms, total 42ms
08-03 14:59:07.611 3623-5845/foto.studio D/dalvikvm﹕ GC_FOR_ALLOC freed 2693K, 21% free 16566K/20716K, paused 92ms, total 92ms
08-03 14:59:09.436 3623-3623/foto.studio D/dalvikvm﹕ GC_FOR_ALLOC freed 2763K, 21% free 16792K/21012K, paused 95ms, total 95ms
08-03 14:59:10.611 3623-3623/foto.studio W/libc﹕ pthread_create failed: couldn't allocate 1040384-byte stack: Out of memory
08-03 14:59:10.611 3623-3623/foto.studio E/dalvikvm﹕ pthread_create (stack size 16384 bytes) failed: Try again
08-03 14:59:10.611 3623-3623/foto.studio D/AndroidRuntime﹕ Shutting down VM
08-03 14:59:10.611 3623-3623/foto.studio W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41c38c08)
08-03 14:59:10.621 3623-3623/foto.studio I/System.out﹕ Uploading Crash Report!
08-03 14:59:10.626 3623-3623/foto.studio W/libc﹕ pthread_create failed: couldn't allocate 1040384-byte stack: Out of memory
08-03 14:59:10.626 3623-3623/foto.studio E/dalvikvm﹕ pthread_create (stack size 16384 bytes) failed: Try again
08-03 15:00:00.426 3623-3635/foto.studio W/libc﹕ pthread_create failed: couldn't allocate 1040384-byte stack: Out of memory
08-03 15:00:00.426 3623-3635/foto.studio E/libutils.threads﹕ androidCreateRawThreadEtc failed (entry=0x4009c559, res=11, errno=0)
(android threadPriority=0)
08-03 15:08:01.106 3623-3658/foto.studio D/dalvikvm﹕ GC_FOR_ALLOC freed 3734K, 25% free 16121K/21312K, paused 170ms, total 174ms
08-03 15:08:01.291 3623-3633/foto.studio E/System﹕ Uncaught exception thrown by finalizer
08-03 15:08:01.291 3623-3633/foto.studio E/System﹕ java.lang.NullPointerException
at org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager.shutdown(ThreadSafeClientConnManager.java:256)
at org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager.finalize(ThreadSafeClientConnManager.java:105)
at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:187)
at java.lang.Daemons$FinalizerDaemon.run(Daemons.java:170)
at java.lang.Thread.run(Thread.java:841)