How to finish current activity in Android

前端 未结 8 1450
长发绾君心
长发绾君心 2020-11-28 03:19

I have an Android application. I am making a loading screen with a progress bar.

I entered a delay in the onCreate method. When the timer finishes, I want to finis

8条回答
  •  广开言路
    2020-11-28 03:38

    I tried using this example but it failed miserably. Every time I use to invoke finish()/ finishactivity() inside a handler, I end up with this menacing java.lang.IllegalAccess Exception. i'm not sure how did it work for the one who posed the question.

    Instead the solution I found was that create a method in your activity such as

    void kill_activity()
    { 
        finish();
    }
    

    Invoke this method from inside the run method of the handler. This worked like a charm for me. Hope this helps anyone struggling with "how to close an activity from a different thread?".

提交回复
热议问题