Jumat, 08 Desember 2017

custom Recent apps Button for android 4.0 above

add this code in your activity


@Overridepublic void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    if (!hasFocus) {
        windowCloseHandler.postDelayed(windowCloserRunnable, 0);    }
}
private void toggleRecents() {
    Toast.makeText(this, "Recent apps", Toast.LENGTH_SHORT).show();    Intent closeRecents = new Intent("com.android.systemui.recent.action.TOGGLE_RECENTS");    closeRecents.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK 
    | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
    ComponentName recents = new ComponentName("com.android.systemui"
    , "com.android.systemui.recent.RecentsActivity");
    closeRecents.setComponent(recents);    this.startActivity(closeRecents);}
public Handler windowCloseHandler = new Handler();public  Runnable windowCloserRunnable = new Runnable() {
    @Override    public void run() {
        ActivityManager am = (ActivityManager) getApplicationContext()
                .getSystemService(Context.ACTIVITY_SERVICE);        ComponentName cn = am.getRunningTasks(1).get(0).topActivity;
        if (cn != null && cn.getClassName().equals("com.android.systemui.recent.RecentsActivity")) {
            toggleRecents();        }
    }
};

or you can use this
but each method has shortcomings and the shorter length of the code does not rule out the possibility of losses

@Overrideprotected void onPause() {
    super.onPause();    ActivityManager activityManager = (ActivityManager) getApplicationContext()
            .getSystemService(Context.ACTIVITY_SERVICE);
    activityManager.moveTaskToFront(getTaskId(), 0);}

good luck and success for your code



Tidak ada komentar:

how to update playonlinux? || bagaimana update playonlinux di linux mint

open terminal wget -q "http://deb.playonlinux.com/public.gpg" -O - | sudo apt-key add - sudo wget http://deb.playonlinux.com/pla...