从“最近使用的应用”中的应用返回到股票启动器,而不是自定义启动器

2022-09-02 14:15:00

我正在创建一个自定义启动器,该启动器用作手机的展台模式。这意味着大多数内容都被隐藏起来,但允许用户访问某些应用程序。我注意到,当我从“最近使用的应用程序”列表中启动应用程序时,当我按下后退按钮时,会出现股票启动器而不是我的自定义启动器。我确保我的自定义启动器是默认启动器,因为这是我按下主页按钮时出现的启动器。有没有人遇到过这个问题?我该如何解决?


答案 1

在我试图自己制作一个自定义启动器时,要产生这个结果,你需要禁用默认的启动器,我能够使用KeyguardManager做到这一点。

package com.themejunky.locker.services;


public class KeyguardService extends Service {

    BroadcastReceiver mReceiver, mBatteryReceiver;

// Intent myIntent;
public class LocalBinder extends Binder {
    public KeyguardService getService() {
        return KeyguardService.this;
    }
}

@Override
public IBinder onBind(Intent intent) {
    return mBinder;
}

private final IBinder mBinder = new LocalBinder();

@Override
public void onCreate() {
    KeyguardManager.KeyguardLock k1;

    KeyguardManager km = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
    k1 = km.newKeyguardLock("IN");
    k1.disableKeyguard();

    KeyguardManager keyguardManager = (KeyguardManager)getSystemService(Activity.KEYGUARD_SERVICE);
    KeyguardManager.KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE);
    lock.disableKeyguard();

    IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    filter.setPriority(999);

    mReceiver = new LockScreenReceiver();
    registerReceiver(mReceiver, filter);

    mBatteryReceiver = new BatteryReceiver();
    IntentFilter filter2 = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
    filter2.addAction(Intent.ACTION_BATTERY_OKAY);
    filter2.addAction(Intent.ACTION_BATTERY_LOW);
    registerReceiver(mBatteryReceiver, filter2);

    super.onCreate();
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    return START_STICKY;
}

@Override
public void onDestroy() {
    unregisterReceiver(mReceiver);
    unregisterReceiver(mBatteryReceiver);
    super.onDestroy();
}

}


答案 2

当我遇到同样的问题时,我发现的唯一解决方案是重新启动设备。当您从最近的应用程序启动应用程序并按后退按钮时,您将看到正确的主屏幕。


推荐