我正在开发一个应用程序,我希望在指定的时间段后注销登录用户。 为此,我使用AsyncTask。但是当线程时间结束时,在android studio日志中,应用程序显示大量日志,然后应用程序在一段时间后自动重启应用程序崩溃。在显示日志应用程序变为静止但未响应任何操作时,该应用程序崩溃并重新启动。
TimeThreadInfo.java
public class TimeThreadInfo {
public String userId;
public Long time;
}
MainActivity.java
Time tm = new Time();
tm.setToNow();
TimeThreadInfo info=new TimeThreadInfo();
info.userId=userId;
info.time=Long.parseLong(Long.toString(tm.toMillis(false)));
TimeThread task=new TimeThread();
task.execute(info);
在MainActivity中,内部类是
private class TimeThread extends AsyncTask<TimeThreadInfo,Void,Void> {
@Override
protected Void doInBackground(TimeThreadInfo... params) {
TimeThreadInfo timeThreadInfo=params[0];
long thredStartTime=timeThreadInfo.time;
Long stopTime=thredStartTime+60000;
while(true){
SharedPreferences myShared=MainActivity.this.getSharedPreferences("my_application",Context.MODE_PRIVATE);
String id=myShared.getString("user_id", "nothing");
Time tm = new Time();
tm.setToNow();
Long currentTime=Long.parseLong(Long.toString(tm.toMillis(false)));
if(id.equalsIgnoreCase(timeThreadInfo.userId)&¤tTime<stopTime) {
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
else{
if(id.equalsIgnoreCase(timeThreadInfo.userId)&¤tTime>=stopTime) {
Config.signout(getApplicationContext());
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
}
else
break;
}
}
return null;
}
}
日志
06-21 18:33:31.265 32204-32209/com.example.farhan.fyp I/dalvikvm: threadid=3: reacting to signal 3
06-21 18:33:31.426 32204-32209/com.example.farhan.fyp I/dalvikvm: Wrote stack traces to '/data/anr/traces.txt'
06-21 18:34:00.965 32204-32204/com.example.farhan.fyp D/dalvikvm: GC_FOR_ALLOC freed 315K, 5% free 12279K/12871K, paused 165ms
06-21 18:34:01.286 32204-32209/com.example.farhan.fyp I/dalvikvm: threadid=3: reacting to signal 3
06-21 18:34:01.286 32204-32209/com.example.farhan.fyp I/dalvikvm: Wrote stack traces to '/data/anr/traces.txt'
06-21 18:34:02.408 32204-32204/com.example.farhan.fyp D/dalvikvm: GC_FOR_ALLOC freed 252K, 4% free 12842K/13319K, paused 72ms
06-21 18:34:02.739 32204-32209/com.example.farhan.fyp I/dalvikvm: threadid=3: reacting to signal 3
06-21 18:34:02.900 32204-32209/com.example.farhan.fyp I/dalvikvm: Wrote stack traces to '/data/anr/traces.txt'
06-21 18:34:03.395 32204-32209/com.example.farhan.fyp I/dalvikvm: threadid=3: reacting to signal 3
06-21 18:34:03.750 32204-32209/com.example.farhan.fyp I/dalvikvm: Wrote stack traces to '/data/anr/traces.txt'
06-21 18:34:03.911 32204-32209/com.example.farhan.fyp I/dalvikvm: threadid=3: reacting to signal 3
06-21 18:34:04.071 32204-32208/com.example.farhan.fyp D/dalvikvm: GC_CONCURRENT freed 241K, 3% free 13872K/14215K, paused 25ms+13ms
06-21 18:34:04.152 32204-32209/com.example.farhan.fyp I/dalvikvm: Wrote stack traces to '/data/anr/traces.txt'
06-21 18:34:04.472 32204-32209/com.example.farhan.fyp I/dalvikvm: threadid=3: reacting to signal 3
06-21 18:34:04.472 32204-32209/com.example.farhan.fyp I/dalvikvm: Wrote stack traces to '/data/anr/traces.txt'
06-21 18:34:04.712 32204-32209/com.example.farhan.fyp I/dalvikvm: threadid=3: reacting to signal 3
06-21 18:34:04.872 32204-32209/com.example.farhan.fyp I/dalvikvm: Wrote stack traces to '/data/anr/traces.txt'
06-21 18:34:05.512 32204-32209/com.example.farhan.fyp I/dalvikvm: threadid=3: reacting to signal 3
06-21 18:34:05.592 32204-32209/com.example.farhan.fyp I/dalvikvm: Wrote stack traces to '/data/anr/traces.txt'
06-21 18:34:05.754 32204-32209/com.example.farhan.fyp I/dalvikvm: threadid=3: reacting to signal 3
06-21 18:34:05.754 32204-32209/com.example.farhan.fyp I/dalvikvm: Wrote stack traces to '/data/anr/traces.txt'
06-21 18:34:06.395 32204-32209/com.example.farhan.fyp I/dalvikvm: threadid=3: reacting to signal 3
06-21 18:34:06.476 32204-32208/com.example.farhan.fyp D/dalvikvm: GC_CONCURRENT freed 672K, 6% free 14824K/15623K, paused 8ms+18ms
06-21 18:34:06.556 32204-32209/com.example.farhan.fyp I/dalvikvm: Wrote stack traces to '/data/anr/traces.txt'
06-21 18:34:06.637 32204-32209/com.example.farhan.fyp I/dalvikvm: threadid=3: reacting to signal 3
06-21 18:34:07.122 32204-32209/com.example.farhan.fyp I/dalvikvm: Wrote stack traces to '/data/anr/traces.txt'
06-21 18:34:07.683 32204-32209/com.example.farhan.fyp I/dalvikvm: threadid=3: reacting to signal 3
06-21 18:34:23.483 32204-32204/com.example.farhan.fyp D/dalvikvm: GC_FOR_ALLOC freed 500K, 4% free 23494K/24263K, paused 153ms
06-21 18:34:23.724 32204-32209/com.example.farhan.fyp I/dalvikvm: threadid=3: reacting to signal 3
06-21 18:34:23.724 32204-32209/com.example.farhan.fyp I/dalvikvm: Wrote stack traces to '/data/anr/traces.txt'
06-21 18:34:24.783 32204-32209/com.example.farhan.fyp I/dalvikvm: threadid=3: reacting to signal 3
06-21 18:34:24.863 32204-32209/com.example.farhan.fyp I/dalvikvm: Wrote stack traces to '/data/anr/traces.txt'
06-21 18:34:25.184 32204-32204/com.example.farhan.fyp D/dalvikvm: GC_FOR_ALLOC freed 479K, 4% free 24610K/25415K, paused 180ms
06-21 18:34:25.344 32204-32209/com.example.farhan.fyp I/dalvikvm: threadid=3: reacting to signal 3
06-21 18:34:25.507 32204-32209/com.example.farhan.fyp I/dalvikvm: Wrote stack traces to '/data/anr/traces.txt'
06-21 18:34:25.747 32204-32204/com.example.farhan.fyp D/dalvikvm: GREF has increased to 301
06-21 18:34:25.827 32204-32209/com.example.farhan.fyp I/dalvikvm: threadid=3: reacting to signal 3
06-21 18:34:26.067 32204-32209/com.example.farhan.fyp I/dalvikvm: Wrote stack traces to '/data/anr/traces.txt'
06-21 18:34:27.033 32204-32209/com.example.farhan.fyp I/dalvikvm: threadid=3: reacting to signal 3
06-21 18:34:27.275 32204-32209/com.example.farhan.fyp I/dalvikvm: Wrote stack traces to '/data/anr/traces.txt'
06-21 18:34:27.515 32204-32208/com.example.farhan.fyp D/dalvikvm: GC_CONCURRENT freed 671K, 3% free 26005K/26759K, paused 8ms+32ms
06-21 18:34:28.077 32204-32209/com.example.farhan.fyp I/dalvikvm: threadid=3: reacting to signal 3
06-21 18:34:28.077 32204-32209/com.example.farhan.fyp I/dalvikvm: Wrote stack traces to '/data/anr/traces.txt'
06-21 18:34:28.880 32204-32209/com.example.farhan.fyp I/dalvikvm: threadid=3: reacting to signal 3
06-21 18:34:28.880 32204-32209/com.example.farhan.fyp I/dalvikvm: Wrote stack traces to '/data/anr/traces.txt'
06-21 18:34:29.521 32204-32204/com.example.farhan.fyp D/dalvikvm: GC_FOR_ALLOC freed 497K, 3% free 27393K/28039K, paused 183ms
06-21 18:34:29.923 32204-32209/com.example.farhan.fyp I/dalvikvm: threadid=3: reacting to signal 3
06-21 18:34:30.083 32204-32209/com.example.farhan.fyp I/dalvikvm: Wrote stack traces to '/data/anr/traces.txt'
06-21 18:34:30.839 32204-32209/com.example.farhan.fyp I/dalvikvm: threadid=3: reacting to signal 3
06-21 18:34:31.000 32204-32209/com.example.farhan.fyp I/dalvikvm: Wrote stack traces to '/data/anr/traces.txt'
06-21 18:34:31.242 32204-32204/com.example.farhan.fyp D/dalvikvm: GC_FOR_ALLOC freed 480K, 3% free 28524K/29191K, paused 146ms
06-21 18:34:31.963 32204-32209/com.example.farhan.fyp I/dalvikvm: threadid=3: reacting to signal 3
06-21 18:34:32.286 32204-32209/com.example.farhan.fyp I/dalvikvm: Wrote stack traces to '/data/anr/traces.txt'
06-21 18:34:32.963 32204-32204/com.example.farhan.fyp D/dalvikvm: GC_FOR_ALLOC freed 476K, 3% free 29627K/30343K, paused 158ms
06-21 18:34:33.043 32204-32209/com.example.farhan.fyp I/dalvikvm: threadid=3: reacting to signal 3
06-21 18:34:38.460 32204-32204/com.example.farhan.fyp I/dalvikvm-heap: Clamp target GC heap from 33.233MB to 32.000MB
06-21 18:34:38.620 32204-32204/com.example.farhan.fyp D/dalvikvm: GC_FOR_ALLOC freed 250K, 3% free 31911K/32647K, paused 326ms
06-21 18:34:38.620 32204-32204/com.example.farhan.fyp I/dalvikvm-heap: Forcing collection of SoftReferences for 449872-byte allocation
06-21 18:34:38.620 32204-32209/com.example.farhan.fyp I/dalvikvm: Wrote stack traces to '/data/anr/traces.txt'
06-21 18:34:38.861 32204-32204/com.example.farhan.fyp I/dalvikvm-heap: Clamp target GC heap from 33.232MB to 32.000MB
06-21 18:34:38.941 32204-32204/com.example.farhan.fyp D/dalvikvm: GC_BEFORE_OOM freed 1K, 3% free 31910K/32647K, paused 265ms
06-21 18:34:38.941 32204-32204/com.example.farhan.fyp E/dalvikvm-heap: Out of memory on a 449872-byte allocation.
06-21 18:34:38.941 32204-32204/com.example.farhan.fyp I/dalvikvm: "main" prio=5 tid=1 RUNNABLE
06-21 18:34:38.941 32204-32204/com.example.farhan.fyp I/dalvikvm: | group="main" sCount=0 dsCount=0 obj=0x409c0460 self=0x12810
06-21 18:34:38.941 32204-32204/com.example.farhan.fyp I/dalvikvm: | sysTid=32204 nice=0 sched=0/0 cgrp=default handle=1074082952
06-21 18:34:38.941 32204-32204/com.example.farhan.fyp I/dalvikvm: | schedstat=( 23506031393 31239932235 5375 ) utm=1965 stm=390 core=0
06-21 18:34:38.941 32204-32204/com.example.farhan.fyp I/dalvikvm: at android.graphics.Bitmap.nativeCreate(Native Method)
06-21 18:34:38.941 32204-32204/com.example.farhan.fyp I/dalvikvm: at android.graphics.Bitmap.createBitmap(Bitmap.java:605)
06-21 18:34:38.941 32204-32204/com.example.farhan.fyp I/dalvikvm: at android.graphics.Bitmap.createBitmap(Bitmap.java:551)
06-21 18:34:38.941 32204-32204/com.example.farhan.fyp I/dalvikvm: at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:437)
06-21 18:34:38.941 32204-32204/com.example.farhan.fyp I/dalvikvm: at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:524)
06-21 18:34:38.941 32204-32204/com.example.farhan.fyp I/dalvikvm: at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:499)
06-21 18:34:38.941 32204-32204/com.example.farhan.fyp I/dalvikvm: at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:351)
06-21 18:34:38.941 32204-32204/com.example.farhan.fyp I/dalvikvm: at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:773)
06-21 18:34:38.941 32204-32204/com.example.farhan.fyp I/dalvikvm: at android.content.res.Resources.loadDrawable(Resources.java:1940)
06-21 18:34:39.021 32204-32204/com.example.farhan.fyp I/dalvikvm: at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
06-21 18:34:39.021 32204-32204/com.example.farhan.fyp I/dalvikvm: at android.view.View.<init>(View.java:2785)
06-21 18:34:39.021 32204-32204/com.example.farhan.fyp I/dalvikvm: at android.view.ViewGroup.<init>(ViewGroup.java:385)
06-21 18:34:39.021 32204-32204/com.example.farhan.fyp I/dalvikvm: at android.widget.LinearLayout.<init>(LinearLayout.java:174)
06-21 18:34:39.021 32204-32204/com.example.farhan.fyp I/dalvikvm: at android.widget.LinearLayout.<init>(LinearLayout.java:170)
06-21 18:34:39.021 32204-32204/com.example.farhan.fyp I/dalvikvm: at java.lang.reflect.Constructor.constructNative(Native Method)
06-21 18:34:39.021 32204-32204/com.example.farhan.fyp I/dalvikvm: at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
06-21 18:34:39.021 32204-32204/com.example.farhan.fyp I/dalvikvm: at android.view.LayoutInflater.createView(LayoutInflater.java:586)
06-21 18:34:39.021 32204-32204/com.example.farhan.fyp I/dalvikvm: at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
06-21 18:34:39.021 32204-32204/com.example.farhan.fyp I/dalvikvm: at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
06-21 18:34:39.021 32204-32204/com.example.farhan.fyp I/dalvikvm: at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
06-21 18:34:39.021 32204-32204/com.example.farhan.fyp I/dalvikvm: at android.view.LayoutInflater.parseInclude(LayoutInflater.java:800)
06-21 18:34:39.021 32204-32204/com.example.farhan.fyp I/dalvikvm: at android.view.LayoutInflater.rInflate(LayoutInflater.java:729)
06-21 18:34:39.021 32204-32204/com.example.farhan.fyp I/dalvikvm: at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
06-21 18:34:39.021 32204-32204/com.example.farhan.fyp I/dalvikvm: at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
06-21 18:34:39.021 32204-32204/com.example.farhan.fyp I/dalvikvm: at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
06-21 18:34:39.021 32204-32204/com.example.farhan.fyp I/dalvikvm: at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:276)
06-21 18:34:39.021 32204-32204/com.example.farhan.fyp I/dalvikvm: at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
06-21 18:34:39.021 32204-32204/com.example.farhan.fyp I/dalvikvm: at com.example.farhan.fyp.MainActivity.onCreate(MainActivity.java:51)
06-21 18:34:39.021 32204-32204/com.example.farhan.fyp I/dalvikvm: at android.app.Activity.performCreate(Activity.java:4466)
06-21 18:34:39.021 32204-32204/com.example.farhan.fyp I/dalvikvm: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
06-21 18:34:39.021 32204-32204/com.example.farhan.fyp I/dalvikvm: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
06-21 18:34:39.021 32204-32204/com.example.farhan.fyp I/dalvikvm: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
06-21 18:34:39.021 32204-32204/com.example.farhan.fyp I/dalvikvm: at android.app.ActivityThread.access$600(ActivityThread.java:123)
06-21 18:34:39.021 32204-32204/com.example.farhan.fyp I/dalvikvm: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
06-21 18:34:39.021 32204-32204/com.example.farhan.fyp I/dalvikvm: at android.os.Handler.dispatchMessage(Handler.java:99)
06-21 18:34:39.021 32204-32204/com.example.farhan.fyp I/dalvikvm: at android.os.Looper.loop(Looper.java:137)
06-21 18:34:39.021 32204-32204/com.example.farhan.fyp I/dalvikvm: at android.app.ActivityThread.main(ActivityThread.java:4424)
06-21 18:34:39.021 32204-32204/com.example.farhan.fyp I/dalvikvm: at java.lang.reflect.Method.invokeNative(Native Method)
06-21 18:34:39.021 32204-32204/com.example.farhan.fyp I/dalvikvm: at java.lang.reflect.Method.invoke(Method.java:511)
06-21 18:34:39.021 32204-32204/com.example.farhan.fyp I/dalvikvm: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-21 18:34:39.021 32204-32204/com.example.farhan.fyp I/dalvikvm: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-21 18:34:39.021 32204-32204/com.example.farhan.fyp I/dalvikvm: at dalvik.system.NativeStart.main(Native Method)
06-21 18:34:39.101 32204-32204/com.example.farhan.fyp D/AndroidRuntime: Shutting down VM
06-21 18:34:39.101 32204-32204/com.example.farhan.fyp W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x409bf1f8)
06-21 18:34:39.342 32204-32204/com.example.farhan.fyp E/AndroidRuntime: FATAL EXCEPTION: main
06-21 18:34:39.342 32204-32204/com.example.farhan.fyp E/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.farhan.fyp/com.example.farhan.fyp.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
06-21 18:34:39.342 32204-32204/com.example.farhan.fyp E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
06-21 18:34:39.342 32204-32204/com.example.farhan.fyp E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
06-21 18:34:39.342 32204-32204/com.example.farhan.fyp E/AndroidRuntime: at android.app.ActivityThread.access$600(ActivityThread.java:123)
06-21 18:34:39.342 32204-32204/com.example.farhan.fyp E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
06-21 18:34:39.342 32204-32204/com.example.farhan.fyp E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:99)
06-21 18:34:39.342 32204-32204/com.example.farhan.fyp E/AndroidRuntime: at android.os.Looper.loop(Looper.java:137)
06-21 18:34:39.342 32204-32204/com.example.farhan.fyp E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:4424)
06-21 18:34:39.342 32204-32204/com.example.farhan.fyp E/AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)
06-21 18:34:39.342 32204-32204/com.example.farhan.fyp E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:511)
06-21 18:34:39.342 32204-32204/com.example.farhan.fyp E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-21 18:34:39.342 32204-32204/com.example.farhan.fyp E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-21 18:34:39.342 32204-32204/com.example.farhan.fyp E/AndroidRuntime: at dalvik.system.NativeStart.main(Native Method)
06-21 18:34:39.342 32204-32204/com.example.farhan.fyp E/AndroidRuntime: Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
06-21 18:34:39.342 32204-32204/com.example.farhan.fyp E/AndroidRuntime: at android.view.LayoutInflater.createView(LayoutInflater.java:606)
06-21 18:34:39.342 32204-32204/com.example.farhan.fyp E/AndroidRuntime: at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
06-21 18:34:39.342 32204-32204/com.example.farhan.fyp E/AndroidRuntime: at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
06-21 18:34:39.342 32204-32204/com.example.farhan.fyp E/AndroidRuntime: at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
06-21 18:34:39.342 32204-32204/com.example.farhan.fyp E/AndroidRuntime: at android.view.LayoutInflater.parseInclude(LayoutInflater.java:800)
06-21 18:34:39.342 32204-32204/com.example.farhan.fyp E/AndroidRuntime: at android.view.LayoutInflater.rInflate(LayoutInflater.java:729)
06-21 18:34:39.342 32204-32204/com.example.farhan.fyp E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
06-21 18:34:39.342 32204-32204/com.example.farhan.fyp E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
06-21 18:34:39.342 32204-32204/com.example.farhan.fyp E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
06-21 18:34:39.342 32204-32204/com.example.farhan.fyp E/AndroidRuntime: at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:276)
06-21 18:34:39.342 32204-32204/com.example.farhan.fyp E/AndroidRuntime: at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
06-21 18:34:39.342 32204-32204/com.example.farhan.fyp E/AndroidRuntime: at com.example.farhan.fyp.MainActivity.onCreate(MainActivity.java:51)
06-21 18:34:39.342 32204-32204/com.example.farhan.fyp E/AndroidRuntime: at android.app.Activity.performCreate(Activity.java:4466)
06-21 18:34:39.342 32204-32204/com.example.farhan.fyp E/AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
06-21 18:34:39.342 32204-32204/com.example.farhan.fyp E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
06-21 18:34:39.342 32204-32204/com.example.farhan.fyp E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
06-21 18:34:39.342 32204-32204/com.example.farhan.fyp E/AndroidRuntime: at android.app.ActivityThread.access$600(ActivityThread.java:123)
06-21 18:34:39.342 32204-32204/com.example.farhan.fyp E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
06-21 18:34:39.342 32204-32204/com.example.farhan.fyp E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:99)
06-21 18:34:39.342 32204-32204/com.example.farhan.fyp E/AndroidRuntime: at android.os.Looper.loop(Looper.java:137)
06-21 18:34:39.342 32204-32204/com.example.farhan.fyp E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:4424)
06-21 18:34:39.342 32204-32204/com.example.farhan.fyp E/AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)
06-21 18:34:39.342 32204-32204/com.example.farhan.fyp E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:511)
06-21 18:34:39.342 32204-32204/com.example.farhan.fyp E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-21 18:34:39.342 32204-32204/com.example.farhan.fyp E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-21 18:34:39.342 32204-32204/com.example.farhan.fyp E/AndroidRuntime: at dalvik.system.NativeStart.main(Native Method)
06-21 18:34:39.342 32204-32204/com.example.farhan.fyp E/AndroidRuntime: Caused by: java.lang.reflect.InvocationTargetException
06-21 18:34:39.342 32204-32204/com.example.farhan.fyp E/AndroidRuntime: at java.lang.reflect.Constructor.constructNative(Native Method)
06-21 18:34:39.342 32204-32204/com.example.farhan.fyp E/AndroidRuntime: Caused by: java.lang.OutOfMemoryError
答案 0 :(得分:0)
使用:
while(true)
通常不是一个好主意。
考虑将它放在您的应用程序类中:
registerActivityLifecycleCallbacks(myActivityLifecycleCallbacks);
然后通过实施
创建myActivityLifecycleCallbacksApplication.ActivityLifecycleCallbacks
并在该类中覆盖:
Handler handler;
@Override
public void notifyUserInteraction(final Activity activity) {
handler.removeCallbacks();
handler.postDelayed(yourLogoutRunnable, 60000);
}
现在,每次用户使用您的应用时,您都将重新启动延迟的任务,如果允许完成,则会将用户注销。
使用Handler调用postDelayed with logout方法和超时。
这里的想法是每次用户触摸应用时取消postDelayed,如果允许runnable运行,它会执行您的注销过程。