Running activity from remote service

╄→гoц情女王★ 提交于 2019-12-20 01:38:34

问题


iam trying to run an activity from diffrent package from my remote service: this is how i implement the 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);
     }
     .....

}

ive also added a line in the manifest of the service:

the service works fine, but i cant run the activity -> PushActivity which is in diffrent package of diffrent application, this is the error:

Activity not found Exception: No Activity found to handle Intent {act=com.pushservice.PushServiceActivity flq=0x10 ...

thanks.

|improve this question

回答1:


You are attempting to open an Activity that has an intent-filter with an action of "com.pushservice.PushActivity". You do not have an Activity that has an intent-filter with an action of "com.pushservice.PushActivity".

The best answer is to not display an activity from a service, since users will be very irritated with you if you interrupt them when they are using the device.




回答2:


You shouldn't call start activity from your service. From 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.



来源:https://stackoverflow.com/questions/2735927/running-activity-from-remote-service

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!