不廢話,上代碼。
//喚醒時(shí)豪直,獲取當(dāng)前界面是哪個(gè)
ActivityManager am =(ActivityManager)App.getContext(). getSystemService(ACTIVITY_SERVICE);
ComponentName cn = am.getRunningTasks(1).get(0).topActivity;
//喚醒的時(shí)候如果在屏保界面潭流,跳轉(zhuǎn)首頁(yè)
if(cn.getClassName().equals("包名.ScreenActivity")){
? ? Intent intent =new Intent(App.getContext(), MainActivity.class);
? ? intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
? ? App.getContext().startActivity(intent);
}
cn.getClassName();//獲取當(dāng)前展示的activity
cn.getPackageName();//獲取當(dāng)前包名
自己開(kāi)發(fā)遇到一個(gè)需求燎潮,因?yàn)橛锌拼笥嶏w喚醒,當(dāng)無(wú)操作待機(jī)進(jìn)入屏保扼倘,在屏保界面時(shí)喚醒a(bǔ)pp确封,需要進(jìn)入首頁(yè),特此記錄再菊。