android - App not getting minimized on home button click -


i want write code on home button clicked user in app.

i written following code:

 @override         public void onattachedtowindow() {             super.onattachedtowindow();             this.getwindow().settype(windowmanager.layoutparams.type_keyguard);                    }       @override         public boolean onkeydown(int keycode, keyevent event) {                   if(keycode == keyevent.keycode_home)             {                //the code want perform.                  toast.maketext(getapplicationcontext(), flag+"in here", toast.length_short).show();              }             return true;         } 

this code gives me toast message, not minize app.

once remove following code:

  @override             public void onattachedtowindow() {                 super.onattachedtowindow();                 this.getwindow().settype(windowmanager.layoutparams.type_keyguard);                        } 

and keep only:

 @override             public boolean onkeydown(int keycode, keyevent event) {                       if(keycode == keyevent.keycode_home)                 {                    //the code want perform.                      toast.maketext(getapplicationcontext(), flag+"in here", toast.length_short).show();                  }                 return true;             } 

it not shows me toast message.

please me.

i tried:

return false

onpause method

but not worked.

you should have code,

 @override             public void onattachedtowindow() {                 super.onattachedtowindow();                 this.getwindow().settype(windowmanager.layoutparams.type_keyguard);                        } 

in code. removing not trigger home key action.

now minimize app, following,

    @override                 public boolean onkeydown(int keycode, keyevent event) {                           if(keycode == keyevent.keycode_home)                     {                        //the code want perform.                          toast.maketext(getapplicationcontext(), flag+"in here", toast.length_short).show();                  intent gotohome= new intent(intent.action_main);                  gotohome.addcategory(intent.category_home);                  gotohome.setflags(intent.flag_activity_new_task);                  startactivity(gotohome);                     }                     return true;                 } 

but think solution no more works higher api levels.


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -