android-service

Huawei device killing my foreground service, even with dontkillmyapp.com's solution

邮差的信 提交于 2019-12-06 02:57:56
问题 I'm developing an app which is basically a location tracking software . When you start it, it saves locations and sending them to a server. The code is working for like 5 years now without any modification, without any errors. It is implemented with a simple foreground service. In the recent months I was getting user reported errors about the service stops randomly on Huawei devices. First I thought it is some kind of rare/new crash on newer androids but there was no error logs at all in

IntentService onHandleIntent() still running after onDestroy() fired

非 Y 不嫁゛ 提交于 2019-12-06 02:46:58
In my preference screen, I want to start a service to download files from the internet when one of the preference is being clicked. If the service is already running (downloading files), then the service should be stopped (cancel download). public class Setting extends PreferenceActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); downloadPref.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference pref) { if (DownloadService.isRunning) { Setting.this.stopService(new Intent

Take a screenshot - Background Service

元气小坏坏 提交于 2019-12-06 02:46:33
问题 I'm trying to take a screenshot using a background service. This service is like a Facebook chathead, but I want it to take an screenshot when I do a click. Preview Picture I've developed some code but it doesn't work. The last I've tried was: private void takeScreenshot() { Date now = new Date(); android.text.format.DateFormat.format("yyyy-MM-dd_hh:mm:ss", now); // image naming and path to include sd card appending name you choose for file String mPath = Environment

Background services causing crash

左心房为你撑大大i 提交于 2019-12-06 02:41:11
My issue might be blatent misunderstanding of services and my use of them, or a poss conflict with other apps. When I start a specific activity, I start two background services - location tracking to give distance travelled, and elapsed timer, both of which are passed to the activity with a BroadcastReceiver . I initiate each service with a Long through the Intent object from my primary Activity : if (!Utils.isServiceRunning(this, TrackService.class)) { Intent i = new Intent(this, TrackService.class); i.putExtra("SUB_ID", submissionID); startService(i); } And I use the following code to detect

Start service in another package without Intent filter

馋奶兔 提交于 2019-12-06 01:45:55
Is there a way to start an Android Service defined in another package without using the Intent-Filter tag in the manifest file? For some reason I would not be able to update the manifest file of the app that contains the Service. If you know the exact package name and service name you can create an Intent with that. The service still needs to be declared in the other manifest though. Intent intent = new Intent(); intent.setClassName("com.example.otherapplication", "com.example.otherapplication.ServiceName"); startService(intent); 来源: https://stackoverflow.com/questions/18603381/start-service

Suppress notifications from a service if activity is running

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-06 01:34:18
问题 I have an Activity and Service that work together in my application. I've configured the service as a remote service (implemented AIDL) so it will keep running even when the Activity isn't visible. The service is responsible for polling a server for data and sending alert notifications when certain criteria are met. I do not want the Service to send these notifications when the Activity is visible. Is there a way for the Service to know the status of any particular activity? Particularly an

How to update an app widget on midnight?

倖福魔咒の 提交于 2019-12-06 01:21:50
问题 My app has a widget that shows today's date and need to be updated on midnight. The widget is defined in the manifest as <manifest> ... <application> ... <receiver android:name=".MyWidgetProviderClass" android:label="MyLabel" > <intent-filter> <action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> </intent-filter> <meta-data android:name="android.appwidget.provider" android:resource="@xml/widget_icon_info" /> </receiver> </application> </manifest> And the widget info file is

Using TYPE_STEP_COUNTER in a background service?

徘徊边缘 提交于 2019-12-06 00:23:41
问题 I'm looking at implementing the step sensor API introduced in Android 4.4 (http://youtu.be/yv9jskPvLUc). However, I am unable to find a clear explanation on what the recommended way to monitor this in the background is? It seems like most examples only show how to do this with an activity while the app is running. I don't particularly need a high frequency of updates - I basically want to log the amount of steps the user has walked every hour to a backend service. Should I just spin up a

FirebaseApp with name [DEFAULT] doesn't exist getting error

拜拜、爱过 提交于 2019-12-05 23:40:36
Hi I am trying to get data on background service of Android. But I am getting this error. Here is my code: public class FirebaseBackgroundService extends Service { FirebaseDatabase database = FirebaseDatabase.getInstance(); private ValueEventListener handler; DatabaseReference myRef = database.getReference("chats"); @Nullable @Override public IBinder onBind(Intent intent) { return null; } @Override public void onCreate() { super.onCreate(); handler = new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { postNotify(dataSnapshot.getValue().toString()); }

Launch service from app start, not activity

旧时模样 提交于 2019-12-05 23:12:34
问题 I want to launch a Service when the app is launched instead of an Activity; and then said Service will launch an Activity . I need to do this because my app needs to be running ALWAYS, and when I say ALWAYS I mean ALWAYS. And the only way I've managed to avoid the OS killing my app is by starting a service as Sticky and should Android kill either my Activity or my Service I'll restart them right away. I found this question but the top answer seems rather clumsy, any one has a better idea? PS: