android – 从“最近的应用程序”启动时,PopUp Activity再次启动
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了android – 从“最近的应用程序”启动时,PopUp Activity再次启动,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2353字,纯文字阅读大概需要4分钟。
内容图文
我有一个在AlarmManager收到警报时启动的PopUp活动.
AlarmReceiver扩展了WakefulBroadcastReceiver:
@Override
public void onReceive(Context context, Intent intent) {
Intent service = new Intent(context, AlarmService.class);
service.putExtras(intent);
// Start the service, keeping the device awake while it is launching.
startWakefulService(context, service);
}
AlarmService扩展了IntentService:
@Override
protected void onHandleIntent(Intent intent) {
Intent i = new Intent();
i.setClass(this, PopUpActivity.class);
startActivity(i);
AlarmReceiver.completeWakefulIntent(intent);
}
PopUpActivity:
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(LayoutParams.FLAG_NOT_TOUCH_MODAL, LayoutParams.FLAG_NOT_TOUCH_MODAL);
getWindow().setFlags(LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH, LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH);
setContentView(R.layout.layout_dialog);
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, ClientConstants.WAKE_LOCK_NOTIFICATION);
// Acquire the lock
wl.acquire();
if (canVibrate){
vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(new long[]{ 0, 200, 500 },0);
}
if (canRing){
mediaPlayer = new MediaPlayer();
try {
mediaPlayer.setDataSource(this, getAlarmUri());
final AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
if (audioManager.getStreamVolume(AudioManager.STREAM_ALARM) != 0) {
mediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
mediaPlayer.prepare();
mediaPlayer.start();
}
} catch (IOException e) {
}
}
findViewById(R.id.dialog_ok_button).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
stopRinging();
finish();
}
});
// Release the lock
wl.release();
}
private void stopRinging(){
if (canRing && mediaPlayer.isPlaying())
mediaPlayer.stop();
if (canVibrate){
vibrator.cancel();
}
}
PopUpActivity从警报管理器启动.如果在应用程序不是活动应用程序时启动PopUpActivity,并且如果用户按下“确定”按钮,则活动将消失.到目前为止,没有什么是错的.问题是,如果用户打开最近的应用程序屏幕并选择活动,则会再次启动新的PopUpActivity.我怎样摆脱这个问题?
解决方法:
当您在清单中声明PopupActivity时,请确保包含android:noHistory =“true”.这意味着只要您打开“最近”,弹出活动就会被忘记,您将在重新打开应用程序时返回到之前的位置.
内容总结
以上是互联网集市为您收集整理的android – 从“最近的应用程序”启动时,PopUp Activity再次启动全部内容,希望文章能够帮你解决android – 从“最近的应用程序”启动时,PopUp Activity再次启动所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。