社区
Android
帖子详情
从Activity中开启Service的问题
lcfeng1982
2011-04-17 08:58:59
本人是android开发开发新手,最近在做一个项目,在一个Activity中调用startService时返回null,要调用的service跟这个Activity不在同一个包中;如果把这个service放入这个Activity所在的包中那么调用就能成功。在Manifest文件中有各个Activity个Service的声明。请问各位大侠这是什么原因造成的?
...全文
452
14
打赏
收藏
从Activity中开启Service的问题
本人是android开发开发新手,最近在做一个项目,在一个Activity中调用startService时返回null,要调用的service跟这个Activity不在同一个包中;如果把这个service放入这个Activity所在的包中那么调用就能成功。在Manifest文件中有各个Activity个Service的声明。请问各位大侠这是什么原因造成的?
复制链接
扫一扫
分享
转发到动态
举报
AI
作业
写回复
配置赞助广告
用AI写文章
14 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
wenlong200817
2012-06-09
打赏
举报
回复
楼主,这个问题解决了没啊,我也遇到过了,只能把包名改成主包的子包了。。
求指教啊!!!!
lcfeng1982
2011-04-25
打赏
举报
回复
这个问题已经解决,可能是我在Manefest.xml文件中把包名写错了。
前一段时间比较忙,没来得及结贴;现在结贴,谢谢大家的积极参与,来者有份!!!
-droidcoffee-
2011-04-18
打赏
举报
回复
[Quote=引用 2 楼 aomandeshangxiao 的回复:]
在不同包里面 activity之间是不能用intent跳转到,可能service 也不行。
[/Quote]
这个帧可以,
Intent intent = new Intent();
第一个参数为 AndroidMinifest.xml文件中配置的package属性,第二个参数为要调转的package + class
intent.setClassName("com.android.activity", "com.android.activity.image.ImageActivity");
his.startActivity(intent);
------
Intent intent = new Intent(this, LocalService.class);
这样子只适合 同一个package的情况
sayyanfu
2011-04-18
打赏
举报
回复
你在manifest里的package属性里写上公共包名com.news_viewer,在后面定义的Activity或者Service标签上写上.类名就行,在程序里import 自己的R就行。
sayyanfu
2011-04-18
打赏
举报
回复
[Quote=引用 2 楼 aomandeshangxiao 的回复:]
在不同包里面 activity之间是不能用intent跳转到,可能service 也不行。
[/Quote]
这个是肯定可以的。
yongyuandeni
2011-04-18
打赏
举报
回复
可以通过broadcast实现,在你activity里通过intent(action);在服务的类里面加上intet-filter。
能够实现的
foley_liao
2011-04-18
打赏
举报
回复
[Quote=引用 2 楼 aomandeshangxiao 的回复:]
在不同包里面 activity之间是不能用intent跳转到,可能service 也不行。
[/Quote]
这个肯定是可以的
prince58
2011-04-18
打赏
举报
回复
[Quote=引用 2 楼 aomandeshangxiao 的回复:]
在不同包里面 activity之间是不能用intent跳转到,可能service 也不行。
[/Quote]
这个是可以的。
prince58
2011-04-18
打赏
举报
回复
跨进程调用别的service,需要用AIDL吧。
xiaofancn
2011-04-18
打赏
举报
回复
http://xiaofancn.iteye.com/blog/1000585
ameyume
2011-04-17
打赏
举报
回复
Intent intent = new Intent(this, com.service.LocalService.class);
这样试试
lcfeng1982
2011-04-17
打赏
举报
回复
[Quote=引用 2 楼 aomandeshangxiao 的回复:]
在不同包里面 activity之间是不能用intent跳转到,可能service 也不行。
[/Quote]
那要用什么,PendingIntent吗?
傲慢的上校
2011-04-17
打赏
举报
回复
在不同包里面 activity之间是不能用intent跳转到,可能service 也不行。
lcfeng1982
2011-04-17
打赏
举报
回复
在Activity中:
Intent intent = new Intent(this, LocalService.class);
ComponentName svr = startService(intent);
if( svr == null)
{
Log.i("startService", "fail");
}
在Manifest文件中:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
android:versionName="1.0" package="com.news_viewer.activity">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name="com.news_viewer.activity.StartUpActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="com.service.RSSDownLoadService" />
<service android:name="com.service.LocalService" />
</application>
</manifest>
在
Activity
中
判断
Service
是否已经运行
正在研究Android,写了一个Demo,需要在一个
Activity
中
启动
service
,感觉应该在启动前判断一下是否服务已经跑起来了,百度到如下代码,留待备份。 //本方法判断自己些的一个
Service
-->...
Service
中
启动
Activity
转自:... 在
Service
中
启动
Activity
,有很多方式,比如隐式启动、显式启动等。 隐式启动
Activity
,需要在manifest.xml
中
为该
Activity
配置 ,如下所示:
记录android开发在
Activity
中
关闭
service
报错的
问题
过程
中
遇到了一点
问题
,就在程序
中
的某个
Activity
中
退出应用程序并关闭
service
(程序在启动时创建了
service
,一直运行于后台,通过socket与服务器通信,其
中
在读取服务器传递过来的数据
中
单独
开启
了线程)时报错,...
在
service
中
获取当前
activity
_震惊!Android IPC 之
Service
还可以这么理解
码农A:看见标题我就震惊了...前言Android四大组件:
Activity
、
Service
、BroadcastReceiver、ContentProvider。它们的作用分别是:
Activity
--->配合View展示界面
Service
--->长时间在后台运行不与用户直接交互...
Service
与
Activity
通信
Service
与
Activity
之间 绑定 通信
Android
80,472
社区成员
91,384
社区内容
发帖
与我相关
我的任务
Android
移动平台 Android
复制链接
扫一扫
分享
社区描述
移动平台 Android
android
android-studio
androidx
技术论坛(原bbs)
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章