我的一个应用程序有一个backgrouod服务,它使用START_STICKY返回代码onStartCommand在系统杀死它时自动重启.似乎这不再适用于Android KitKat.这有什么解决方案吗?我应该在Kitkat做一些不同的事情来保持服务的运行吗?
注意:在Android-Devlopers小组中有一个关于从最近的应用列表行为中滑动应用程序的类似讨论.这两个问题可以相关吗? https://groups.google.com/forum/#!topic/android-developers/H-DSQ4-tiac
编辑:看到Android问题跟踪器上有开放的错误:
https://code.google.com/p/android/issues/detail?id=63793 https://code.google.com/p/android/issues/detail?id=63618
Edit2:即使服务正在运行startForeground,在单独的进程android:stopWithTask="false"中使用AndroidManifest.xml文件中的标志,也会发生同样的情况......
Edit3:Android问题跟踪器上的更多相关错误:
https://code.google.com/p/android/issues/detail?id=62091 https://code.google.com/p/android/issues/detail?id=53313 https://code.google. COM/p /安卓/问题/细节?ID = 104308
是否有某种解决方法来获得以前的行为?
我已将我的应用程序上传到谷歌播放,但用户报告了以下异常
java.lang.RuntimeException:WakeLock未锁定C2DM_LIB.当我尝试释放时发生此异常WakeLock.任何人都可以告诉可能是什么问题.
我想创建一个服务,它将在一个单独的线程上运行(而不是在UI线程上),所以我实现了一个将扩展IntentService的类.但我没有运气.这是代码.
public class MyService extends IntentService {
public MyService(String name) {
super(name);
// TODO Auto-generated constructor stub
}
@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
Log.e("Service Example", "Service Started.. ");
// pushBackground();
}
@Override
public void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
Log.e("Service Example", "Service Destroyed.. ");
}
@Override
protected void onHandleIntent(Intent arg0) {
// TODO Auto-generated method stub
for …Run Code Online (Sandbox Code Playgroud) 我Service在我的应用程序中使用它需要运行,直到我的应用程序被卸载,但问题是它被操作系统杀死.
我们怎样才能防止它被操作系统杀死?或者,如果它被杀死,我们可以通过编程方式再次重启该服务吗?
我对Android开发很新.
什么时候创建Android服务而不是仅使用简单的Singleton类是个好主意?
以数据层下载来自互联网的信息为例.
对于某些情况,使用服务似乎太多了,但有时我可能需要访问,Context因此我对如何设计应用程序有点不确定.
我试图从IntentService在通知区域中发布带有自定义视图的通知,并获取IntentService错误.
这是我在做的事情Couldn't expand RemoteView:
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
icon = R.drawable.icon;
tickerText = "data upload in progress";
contentView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.notiflayout);
contentView.setImageViewResource(R.id.image, R.drawable.icon);
contentView.setTextViewText(R.id.text, "Hello");
contentView.setProgressBar(R.id.progressBar, 100, 10, false);
whatNext = PendingIntent.getActivity(getApplicationContext(), 0, new Intent(getApplicationContext(), starterActivity.class), 0);
notification = new Notification(icon, tickerText, System.currentTimeMillis());
notification.contentView = contentView;
notification.contentIntent = whatNext;
Run Code Online (Sandbox Code Playgroud)
我打电话onCreate()给notify(),并取消通知onHandleIntent().
我已经验证此代码可以在一个独立的应用程序中运行,该应用程序没有onDestroy().这样做IntentService是以某种方式给予麻烦.
有人可以解释一下我做错了什么吗?
谢谢!
我正在开发一个Android应用程序.我正在使用android 2.2
在我的应用程序中,我正在捕获GPS数据并以1小时的时间间隔将其发送到服务.如果用户退出应用程序,它也可以正常工作(这是必需的).
我正在使用2个服务(用户定义),一个用于捕获GPS数据,另一个用于发送到服务器.
在这里我怀疑
在服务中,我们可以使用共享首选项.
如果我们将任何数据存储在应用程序的任何活动中的共享首选项中,我们是否可以在共享首选项的帮助下使用该服务中的数据?
如何Service检查其中一个应用程序Activity是否在前台运行?
我有一个使用自定义Loader和Cursor设置的数据加载系统,它在Activities和Fragments中工作得很好但是在Service中没有LoaderManager(我可以找到).有谁知道为什么LoaderManager被排除在服务之外?如果没有办法解决这个问题?
android android-service android-fragments android-loadermanager
根据Google开发人员在我的应用中实施Firebase的说明,我注意到android lint抱怨.
我们的想法是,我们必须实现两个从Firebase服务继承的服务:
public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService { ... }
public class MyFirebaseMessagingService extends FirebaseMessagingService { ... }
Run Code Online (Sandbox Code Playgroud)
然后在清单中注册这些服务.但是,它并不完美.特别是,这两个推荐的AndroidManifest.xml服务条目不包含任何特殊权限:
<service android:name=".MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<service android:name=".MyFirebaseInstanceIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
Run Code Online (Sandbox Code Playgroud)
所以linter说:
导出的服务(设置为exported = true或包含intent-filter且未指定exported = false的服务)应定义实体必须具有的权限才能启动服务或绑定到该服务.没有这个,任何应用程序都可以使用此服务.
我应该只将此属性添加到每个服务标记并完成它
tools:ignore="ExportedService"
Run Code Online (Sandbox Code Playgroud)
或者在这种情况下有更好的方法吗?我的意思是,公开这些特定的Firebase派生服务是否安全?
android android-service android-lint firebase firebase-cloud-messaging