我有一个服务类.我已将此类导出到jar,并且已将jar嵌入到我的客户端应用程序中.
需要时,我会调用服务类.当我尝试这样做时,我收到以下错误:
Unable to start service Intent {comp={com.sample.service/com.sample.service.serviceClass}} : not found
Run Code Online (Sandbox Code Playgroud)
除了服务类之外,我还有其他类,我可以访问它(创建该类的对象),它们位于同一个jar中.
我觉得我错过了我的配置或清单中的一些东西.
请帮我识别一下.我的代码如下:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent () ;
intent.setClassName("com.sample.service" ,"com.sample.service.serviceClass") ;
this.startService(intent) ; // when I call this line I get the message...
// binding other process continue here
}
Run Code Online (Sandbox Code Playgroud)
客户端manifest.xml
<service android:name="com.sample.service.serviceClass"
android:exported="true" android:label="@string/app_name"
android:process=":remote">
<intent-filter><action android:name="com.sample.service.serviceClass"></action>
</intent-filter>
</service>
Run Code Online (Sandbox Code Playgroud)
提前谢谢,
Vinay
我正在构建一个应用程序,它会在用户醒着的时候以特定的时间间隔触发通知.
我在服务中运行了一个alarmManager.通过按钮单击主活动显式启动该服务,并使alarmManager在特定时间内执行通知.如何在一天中的某些时段停止通知?例如,当用户正在睡觉时,我不希望触发这些通知.
我目前以用户设置的间隔发送通知的代码低于(已删除导入....已经足够长了):
public class FartSmackinChunks extends Service {
public Notification scheduleNotification;
public AlarmManager alarmScheduleManager;
public PendingIntent alarmScheduleIntent;
private Boolean autoUpdateBoolean = true;
private int intervalsGoneByInt = 0;
private Notification notification;
public static final int NOTIFICATION_ID = 1;
@Override
public void onCreate() {
// TODO: Actions to perform when service is created.
int icon = R.drawable.icon;
String tickerText = "INTERVAL FIRED";
long when = System.currentTimeMillis();
scheduleNotification = new Notification(icon, tickerText, when);
alarmScheduleManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
String ALARM_ACTION;
ALARM_ACTION = ScheduleAlarmReceiver.ACTION_REFRESH_SCHEDULE_ALARM;
Intent …Run Code Online (Sandbox Code Playgroud) 我已经到了离秃顶几步之遥的地步......
我正在尝试运行一项服务,检查我工作的服务器是否正在运行.它应该每5分钟做一次.
我经历过TimerTask,ScheduledExecutorService,最后是Handler.他们都工作"好"几个小时,除了一些不准确,1-5分钟关闭,然后突然"计时器"停止射击.
现在,我已经读过调度程序会在遇到未被捕获的异常时停止,并且我确定TimerTask的情况也是如此 - 但是检查日志文件,根本没有任何异常......
当我下班回家时,我决定用Handler做一个实验.
我创建了2个处理程序,一个将运行代码来检查服务器并一次增加一个int.另一个只是记录所述int的值,以便在遇到异常时不停止(我看不出它会怎么样).
它运行良好,通常1-5分钟不准确,几个小时然后停止,下面是日志的最后一行:
02-07 20:03:25.892 D/dalvikvm( 992): GC_EXPLICIT freed 192K, 53% free 4295K/9031K, external 3755K/4825K, paused 114ms
02-07 20:03:35.572 D/dalvikvm( 5472): GC_EXPLICIT freed <1K, 54% free 2895K/6279K, external 2002K/2137K, paused 61ms
02-07 20:04:42.212 V/ServerChecker(12568): Timer triggered
02-07 20:04:42.212 V/ServerChecker(12568): Checking: linux15
02-07 20:04:44.152 V/ServerChecker(12568): Checked: linux15
02-07 20:04:44.152 V/ServerChecker(12568): Checking: linux1
02-07 20:04:44.462 V/ServerChecker(12568): Checked: linux1
02-07 20:04:44.462 V/ServerChecker(12568): Checking: linux12
02-07 20:04:44.762 V/ServerChecker(12568): Checked: linux12
02-07 20:04:44.762 V/ServerChecker(12568): Checking: linux9
02-07 20:04:45.072 V/ServerChecker(12568): …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用带有pendingIntent的Alarmmanager启动服务.我坚持使用Unable to start service Intent { flg=0x4 cmp=com.UserLogin/.BgService (has extras) }: not found
错误我已经google搜索并在stackoverflow中搜索了一些关于此错误的问题,但这些解决方案并不适用于我.StackoverFlow,在这里输入链接描述,请检查一次.
服务类别:
public class BgService extends Service {
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
}
@Override
public void onStart(Intent intent, int startId) {
// TODO Auto-generated method stub
System.out.println("OnStart");
super.onStart(intent, startId);
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// …Run Code Online (Sandbox Code Playgroud) 我有一个IntentService从服务器下载数据,我希望IntentService以一定的间隔检查服务器更新.但是以下帖子建议不要重复Service使用a Timer- 而是强调使用AlarmManager:
为什么我的服务不适用于Android?(我只想记录5秒钟的东西)
从Android的参考手册中,IntentService被描述为:
IntentService是服务的基类,可根据需要处理异步请求(表示为Intents).客户端通过startService(Intent)调用发送请求; 根据需要启动服务,使用工作线程依次处理每个Intent,并在工作失败时自行停止.
这种"工作队列处理器"模式通常用于从应用程序的主线程卸载任务.存在IntentService类以简化此模式并处理机制.要使用它,请扩展IntentService并实现onHandleIntent(Intent).IntentService将接收Intents,启动工作线程,并根据需要停止服务.
所有请求都在一个工作线程上处理 - 它们可能需要多长时间(并且不会阻止应用程序的主循环),但一次只能处理一个请求.
我不太明白的部分是为什么不允许使用Timer重复执行IntentService(帖子有针对a Service而不是a的问题),IntentService因为它创建了自己的工作线程以供执行.允许在一个Timer内使用IntentService吗?或者是AlarmManagers定期执行的唯一解决方案IntentService?
对此的解释将是最受欢迎的.