0
我有兩個活動1)FrmHome,我有senTtoback 2)我想從服務打開的ScreenLock。當服務調用屏幕解鎖時,活動將在後臺打開。當我點擊應用程序時,我可以看到Screenlock Activity。我想屏幕鎖的活動應該拿出放在上面,而不攻上的應用程序如何從服務帶上活動
這裏是
public class FrmHome extends ActionBarActivity {
BroadcastReceiver mybroadcast = new BroadcastReceiver() {
//When Event is published, onReceive method is called
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Log.i("[BroadcastReceiver]", "MyReceiver");
if(intent.getAction().equals(Intent.ACTION_USER_PRESENT)){
Log.i("[BroadcastReceiver]", "Screen ON");
Intent intent1 = new Intent(context, ScreenLock.class);
intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent1);
}
else if(intent.getAction().equals(Intent.ACTION_SCREEN_OFF)){
Log.i("[BroadcastReceiver]", "Screen OFF");
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_frm_home);
// registerReceiver(mybroadcast, new IntentFilter(Intent.ACTION_SCREEN_ON));
registerReceiver(mybroadcast, new IntentFilter(Intent.ACTION_USER_PRESENT));
}
}
我的新的活動在後臺打開服務 和處理程序。當我點擊應用程序時,我可以看到新的屏幕鎖定活動。但它不是自動前來的
但我想打開另一個活動(Screenlock),並且我已發回我的主要活動(FrmHome)。 –
對不起,你解釋的場景不清楚!你可以使用'startActivity'來打開你想要的任何活動。這個函數既可以從服務或活動中調用,也可以默認創建一個活動的新實例並顯示它。 –
看我有兩個活動1)FrmHome,我有senTtoback 2)我想從服務打開的ScreenLock。當服務調用屏幕解鎖時,活動將在後臺打開。當我點擊應用程序時,我可以看到Screenlock Activity。我希望ScreenLock活動應該在沒有點擊應用程序的情況下出現 –