2

I'm writing a simple application and I've a problem. My application has to protect, when somebody want to close it. If somebody wants to close app, he has to write a password. It's my simple code. How can I add function, that when somebody wants close app and he will has to write password? I'm new developer, who's programming in Java, so I'm sorry my bad knowledge.

Here is my app:

package com.example.my_first_app;

import android.os.Bundle;
import android.os.Handler;
import android.app.Activity;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebView;

public class MainActivity extends Activity {

    private WebView mWebView;

    Handler handler = new Handler();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mWebView = (WebView) findViewById(R.id.activity_main_webview);
        mWebView.loadUrl("http://google.com");
    }

}
Bergi
  • 630,263
  • 148
  • 957
  • 1,375
JakubKubera
  • 426
  • 1
  • 3
  • 19
  • what do you want to do, if someone force quit the application? You can't stop that: see for example: https://mobileroadie.zendesk.com/hc/en-us/articles/200091926-How-To-Force-Quit-Android-Apps – quant Jan 30 '14 at 00:03
  • I'm not sure I'd want this in an app I installed. What is this being used for? What should happen if the device is turned off and on? – Richard Tingle Jan 30 '14 at 00:04

1 Answers1

1

Just need to have a button that will close your app and display a Alert that ask for the password. Also you will need to Override the back button of the phone and implement the same behavior( display a alert that ask for a password). Keep in mind that you cannot Override the functionality of the Home button for security reasons and you will face this scenario: User exits app using Home button-> go to settings-> apps->your app->force close(depends on the android version).

Override back button: How to disable back key button in Android

and Android Back button code never executed

Community
  • 1
  • 1
Tobiel
  • 1,543
  • 12
  • 19