简体   繁体   English

崩溃后Android应用程序重启

[英]Android Application restart after crash

I am developing an application, in which i want to logout logged-in user after specified time period. 我正在开发一个应用程序,我想在指定的时间段后注销登录用户。 For this purpose i use AsyncTask. 为此,我使用AsyncTask。 But when thread time finish, in android studio logs, application shows lots of logs and then application crashes after a while application restart automatically. 但是当线程时间结束时,在android studio日志中,应用程序显示大量日志,然后应用程序在一段时间后自动重启应用程序崩溃。 While showing logs application becomes still and does not respond to any action, after that application crashes and restart. 在显示日志应用程序变为静止但未响应任何操作时,该应用程序崩溃并重新启动。

TimeThreadInfo.java TimeThreadInfo.java

public class TimeThreadInfo {
public String userId;
public Long time;

} }

MainActivity.java 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);

In MainActivity inner-class is 在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)&&currentTime<stopTime) {
                    try {
                        Thread.sleep(10000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                else{
                    if(id.equalsIgnoreCase(timeThreadInfo.userId)&&currentTime>=stopTime) {
                        Config.signout(getApplicationContext());

                        Intent intent = new Intent(getApplicationContext(), MainActivity.class);
                        startActivity(intent);
                    }
                    else
                        break;
                }
            }
            return null;
        }
    }

Logs 日志

    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

using: 使用:

while(true) 

usually isn't a great idea. 通常不是一个好主意。

Consider putting this in your Application Class: 考虑将它放在您的应用程序类中:

registerActivityLifecycleCallbacks(myActivityLifecycleCallbacks);

Then create myActivityLifecycleCallbacks by implementing 然后通过实现创建myActivityLifecycleCallbacks

Application.ActivityLifecycleCallbacks 

and override in that class: 并覆盖该类:

    Handler handler;

    @Override
        public void notifyUserInteraction(final Activity activity) {

            handler.removeCallbacks();
            handler.postDelayed(yourLogoutRunnable, 60000);

        }

Now every time the user uses your app - you'll be restarting a delayed task that if it's allowed to complete, it will log the user out. 现在,每次用户使用您的应用程序时 - 您将重新启动延迟任务,如果允许完成,则会将用户注销。

Using a Handler call postDelayed with the logout method and the timeout. 使用Handler调用postDelayed with logout方法和超时。

The idea here is to cancel that postDelayed every time the user touches the app, and if the runnable is allowed to run, it does your logout process. 这里的想法是每次用户触摸应用程序时取消postDelayed,如果允许runnable运行,它会执行您的注销过程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM