2

Want to lock activity operations, if user do tap on Yes in AlertDialog, but nothing seems happen when i click on Yes.

I am following this solution

AlertDialog.Builder alertDialog = new AlertDialog.Builder(AlertDialogActivity.this);

        // Setting Dialog Title
        alertDialog.setTitle("Confirm Delete...");

        // Setting Dialog Message
        alertDialog.setMessage("Are you sure you want delete this?");

        // Setting Icon to Dialog
        alertDialog.setIcon(R.drawable.delete);

        // Setting Positive "Yes" Button
        alertDialog.setPositiveButton("YES", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog,int which) {

           PackageManager pm = getPackageManager(); 
                    pm.setComponentEnabledSetting(new ComponentName(getApplicationContext(), com.example.lock.MainActivity.class),
                                                  PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
            }
        });

        // Setting Negative "NO" Button
        alertDialog.setNegativeButton("NO", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
            // Write your code here to invoke NO event
            dialog.cancel();
            }
        });

        // Showing Alert Message
        alertDialog.show();
Community
  • 1
  • 1
Sona
  • 21
  • 2
  • 1) Edit : MainActivity.class instead of getApplicationContext() 2) Share log cat messages when you touch button (onclick) – Ayub Jul 18 '14 at 06:14

4 Answers4

0

Use this. it works :)

` try using this flags to disable lock screen when the activity is started.

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD| WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);

Guru
  • 186
  • 14
0

Actually, I don't think it's possible. Of course you can override onBackPressed method of the Activity so user will not be able to navigate back. Also you can set FullScreenMode to hide status bar from user. However, that's very hard to intercept Home key. It's by Android design, so user will always be able to go to the HomeScreen.

So generally, I would recommend using ProgressDialog (http://developer.android.com/reference/android/app/ProgressDialog.html ) , you can even setCancelable(false) to prevent it being dismissed by "Back". But Home will still minimize your app and go to the homescreen.

nobalG
  • 4,544
  • 3
  • 34
  • 72
  • i think you have not read my question, that's all i know, my concern is how to enable/disable activity, user can't do press on button available in activity.... – Sona Jul 18 '14 at 06:54
0

It seems like that creating new component may causes the problem. Getting context in the dialog may work differently as your thought.

Follow this link Hide application icon. Or edit codes getting a context.

private static final ComponentName LAUNCHER_COMPONENT_NAME = new ComponentName("your.package.name", "your.package.name.Launcher");

....

getPackageManager().setComponentEnabledSetting(LAUNCHER_COMPONENT_NAME,
                PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                PackageManager.DONT_KILL_APP);
Community
  • 1
  • 1
theWook
  • 843
  • 9
  • 22
-1

Instead of giving the getApplicationContext() to fetch the context of the current class give ClassName.this

Mohammed Rampurawala
  • 3,033
  • 2
  • 22
  • 32
  • Simply because it is referencing to the context of dialog class. And with the help of LogCat try to check it out that yes button listener is running or not. – Mohammed Rampurawala Jul 18 '14 at 07:04