Disable back button in Android(Not working)

前端 未结 3 871
囚心锁ツ
囚心锁ツ 2021-01-24 02:59
package com.my.app ;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
         


        
相关标签:
3条回答
  • 2021-01-24 03:23

    I can't see a problem with your back button disabling. But there is another problem that may cause a part of this issue you are doing File IO in the UI Thread of your App.

    Android has one UI Thread that does all the painting of your UI. If you block this thread through writing large files to the disk or reading bitmaps from the disk the phone UI will freeze and not react on user input until the heavy work is done.

    I recommend to read this article on responsiveness to learn more about not blocking the UI Thread.

    0 讨论(0)
  • 2021-01-24 03:35

    You can intercept the BackButton inside your own App, ONLY! As I see, you are starting some kind of CameraApp, that should pick a picture for you. You have NO control over the CameraActivity's BackButton. Your screen Has an ImageView, but you never set a Bitmap to it. The disabling of the BackButton works, as you could NOT go out of your screen and have to "kill" it via a TaskManager. The BackButton has no functionality inside your Activity.

    0 讨论(0)
  • 2021-01-24 03:37

    try this code for disable back button

    @Override
        public boolean onKeyDown(int keyCode, KeyEvent event) 
        {
            if(keyCode==KeyEvent.KEYCODE_BACK)
            {
                return true;
            }
            else
            {
                return super.onKeyDown(keyCode, event);
            }
        }
    

    Capture Image from Camera and Display in Activity

    0 讨论(0)
提交回复
热议问题