gpt4 book ai didi

android - 从远程服务运行 Activity

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:10:02 24 4
gpt4 key购买 nike

我正在尝试从我的远程服务的不同包中运行一个 Activity :这就是我实现 service.java 的方式

  public class CurrencyService extends Service
{
public class CurrencyServiceImpl extends ICurrencyService.Stub
{

int CALL_PUSH_SERVICE_ACTIVITY=10;


@Override
public void callSomeActivity(int activityId) throws RemoteException
{
Intent pushActivity=new Intent("com.pushservice.PushActivity");
pushActivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

startActivity(pushActivity);
}
.....

我还在服务 list 中添加了一行:

服务工作正常,但我无法运行 Activity -> PushActivity,它位于不同应用程序的不同包中,这是错误:

找不到 Activity 异常:找不到处理 Intent {act=com.pushservice.PushServiceActivity flq=0x10 的 Activity ...

谢谢。

最佳答案

您不应该从您的服务中调用开始 Activity 。来自 Android developers best practice :

Instead of spawning Activity UIs directly from the background, you should instead use the NotificationManager to set Notifications. These will appear in the status bar, and the user can then click on them at his leisure, to see what your application has to show him.

关于android - 从远程服务运行 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2735927/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com