歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android 用Launcher啟動應用的方式

Android 用Launcher啟動應用的方式

日期:2017/3/1 10:04:17   编辑:Linux編程

在做展訊平台的時候遇到四葉草鎖屏,下滑可以快速進入拍照應用,經調試發現每次打開都是新的activity,並沒有還原之前鎖屏之前相機的狀態,通過代碼跟蹤和調試發現,與Intent設置啟動參數有關,改動點見文中fix begin和fix end 標志:

public void onTrigger(View v, Intent intent) {

if(mCallback!=null) {
Log.d("cara","onTrigger mCallback="+mCallback);
mCallback.pokeWakelock();

mStatus1.setVisibility(View.GONE);
mStatus2.setVisibility(View.GONE);
mDragHint.setVisibility(View.VISIBLE);

mIntent = null;
if(intent != null){
mIntent = new Intent(intent);
//fix begin
mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
mIntent.addCategory(Intent.CATEGORY_LAUNCHER);
//fix end
mContext.startActivity(mIntent);
}


mHandler.postDelayed(new Runnable() {
public void run() {
if(mCallback!= null)
mCallback.goToUnlockScreen();

}
}, 250);
}
}

onTrigger函數是每次滑動到屏幕到一個解鎖位置(比如滑動到相機應用或者滑動到解鎖點的時候)會觸發這個函數

Intent設置這樣的參數後就相當於從Launcher裡面進入應用了,可以完美的還原相機應用之前的狀態。

Copyright © Linux教程網 All Rights Reserved