从服务开始活动花费的时间太长 [英] Start activity from service takes too long

查看:69
本文介绍了从服务开始活动花费的时间太长的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Service,当一个功能提供给我true时,它将启动一个新的Activity,但需要5秒钟...

I have a Service that when one function gives to me true it will start a new Activity but it takes like 5 seconds...

我已经阅读了有关 issue 的信息,并且在此示例可避免"此错误.

I've read about this issue, and I've found on StackOverflow this example to "avoid" this bug..

Intent intent = new Intent(this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
try {
   pendingIntent.send();
} catch (PendingIntent.CanceledException e) {
   e.printStackTrace();
}

,但遗憾的是它不能更快​​地启动Activity,我不需要立即进行操作(如果可能的话最好),但是我不想等待+5秒来启动新的Activity,您知道如何避免这种情况吗?

but sadly it doesn't start the Activity faster, I don't need to be inmmediate (better if it's possible), but I don't want to wait +5 seconds to launch the new Activity, do you knwo any trick to avoid this?

我正在使用PendingIntent,因为我发现那个说它应该解决此问题的人: 从开始活动按下HOME按钮后无需延迟5秒钟即可进行服务

I'm using PendingIntent because I've found that guy that said that it should solve this issue : Starting an activity from a service after HOME button pressed without the 5 seconds delay

如果我按back button键,它会自动启动,延迟为0,但我想按home button键.

If I press back button it launch it autommatically, 0 delay, but I'm looking pressing the home button.

推荐答案

我还没有到处评论,因此我将这种类似问题的解决方案作为答案

I cannot comment everywhere yet, so I'm putting this solution of a similar problem as an answer

经过大量挖掘,找出了问题的原因.显然 这不是错误,它是一项不允许服务或 广播接收者可以在回家后进行长达5秒钟的活动 按下按钮.没有简单的方法可以克服这个问题.

After much digging, found out the cause of the problem. Apparently it's not a bug, it is a feature which does not allow Services or BroadcastReceivers to launch activities for up to 5 seconds after home button is pressed. No easy way to overcome this.

更多信息在这里: https://code.google.com/p/android/issues/detail ?id = 4536

More info here: https://code.google.com/p/android/issues/detail?id=4536

我用添加到Windows的窗口管理器中的窗口替换了活动 正在运行的服务.这不会造成任何延迟.

I replaced the activity with a Window added to the window manager of the running service. This does not cause any delay.

源链接 Stackoverflow

这篇关于从服务开始活动花费的时间太长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆