android-service

PendingIntent does not send Intent extras

送分小仙女□ 提交于 2019-11-28 03:52:34
My MainActicity starts RefreshService with a Intent which has a boolean extra called isNextWeek . My RefreshService makes a Notification which starts my MainActivity when the user clicks on it. this looks like this: Log.d("Refresh", "RefreshService got: isNextWeek: " + String.valueOf(isNextWeek)); Intent notificationIntent = new Intent(this, MainActivity.class); notificationIntent.putExtra(MainActivity.IS_NEXT_WEEK, isNextWeek); Log.d("Refresh", "RefreshService put in Intent: isNextWeek: " + String.valueOf(notificationIntent.getBooleanExtra(MainActivity.IS_NEXT_WEEK,false))); pendingIntent =

Unit testing Activity.startService() call?

旧城冷巷雨未停 提交于 2019-11-28 03:13:38
问题 Attempting to write my first Android-by-TDD app (I've written a few small Android apps without TDD, so am familiar with the environment), but I can't seem to get my head around how to write my first test. The scenario: I have an activity, TasksActivity, and a service, TasksService. I need to test that TasksActivity starts TasksService in its onStart() method. The test I've written is this: public class ServiceControlTest extends ActivityUnitTestCase<TasksActivity>{ public ServiceControlTest()

BroadcastReceiver dies with app

夙愿已清 提交于 2019-11-28 02:25:02
If i let the phone sit for a long time like 15 minutes i lose my receiver but i thought it was to persist like a service after being killed for memory. Manifest: <receiver android:name=".WearableReceiver" android:enabled="false"> <intent-filter> <action android:name="com.example.johnbravado.MESSAGE_PROCESSED"/> </intent-filter> </receiver> In Activity to start receiver ComponentName component = new ComponentName(CounterActivity.this, WearableReceiver.class); getPackageManager() .setComponentEnabledSetting(component, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);

Android:sound pool and service

你说的曾经没有我的故事 提交于 2019-11-28 02:12:38
I have create the service which implement the media player class to play the back ground music.But now i want to convert into sound pool so that multiple sound can be played. can help any on which can provide me the some link of source code? Thanks in Advance. Just i have implemented the service with background sound,i have check the code from http://android-er.blogspot.com/2010/11/play-audio-resources-using-soundpool.html and http://developer.android.com/guide/topics/fundamentals/bound-services.html public class LocalService extends Service { // Binder given to clients private final IBinder

FCM onMessageReceived not calling Android

…衆ロ難τιáo~ 提交于 2019-11-28 01:51:06
问题 I am facing one problem while implementing FCM in Android application. Everything works fine, my service onMessageReceived() is not calling. But I am getting following logs when I send a message from my Java Server. 08-25 12:14:53.216 20482-20482/com.cognisun.sas D/ActivityThread: BDC-Calling onReceive: intent=Intent { act=com.google.android.c2dm.intent.RECEIVE flg=0x10000010 pkg=com.cognisun.sas cmp=com.cognisun.sas/com.google.firebase.iid.FirebaseInstanceIdReceiver (has extras) }, receiver

Get Exception when showing Alert Dialog from Service - Unable to add window — token null is not for an application

前提是你 提交于 2019-11-28 01:11:51
Get Exception when showing Alert Dialog from Service. Following is the code in my Service class: I am trying to show an AlertDialog. But I get the error: Unable to add window -- token null is not for an application I am also attaching snapshot of my Log to this Question. if(!mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)&& !mLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)){ Log.d("TrackingService","H: Exception after this"); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage("Your GPS seems to be disabled, do you want to enable

Oreo - Starting a service in the foreground

旧时模样 提交于 2019-11-28 00:24:55
问题 I have created a service that tracks the device's location as it moves. The service is started in by an Activity that binds to it, and in this activity there is a "Start Tracking" button. When this button is pressed, I need the service to start in the foreground, so that it stores the Locations that the device has moved to, even if the Activity that binds to it is closed, or the app is minimised. I understand that for the Service to be in the foreground, a notification must be displayed. I

Restart service after force stop

耗尽温柔 提交于 2019-11-28 00:05:39
I am developing an application which is used as application locker, an app which is able to protect other installed apps by asking the user for a password on opening those apps, my app is here The problem is that the application can be easily skipped by force close it from the android task manager, how can I overcome this? Also what is the best way to check for a new application open, to make a service which check every one second for the app on the top of tasks or to fire alarm with alarm manager every second to make the check. Ronak Mehta Updated : Restart service after force stop Answer :

When can onTaskRemoved() be called?

送分小仙女□ 提交于 2019-11-27 23:57:44
问题 The docs state that This is called if the service is currently running and the user has removed a task that comes from the service's application. It seems as if it is only called when the app is swiped away from the recent task list. Pressing the back button until all Activities are destroyed in the task does not cause this to be called. Are there other scenarios where this could be called? 回答1: Pressing the back button until all Activities are destroyed in the task does not cause this to be

Service: onTaskRemoved not called if started with bindService

蹲街弑〆低调 提交于 2019-11-27 23:11:58
问题 I have a Service in which the onTaskRemoved() method has been implemented. When the service is started with startService() the function onTaskRemoved() is called when the app is removed from the recent-apps-list by swipe. But if the service is started with bindService() , then onTaskRemoved() never called. How can I make the Service call onTaskRemoved() when app removed from recent-apps-list by swipe after it has been started with bindService() ? Android calls the following lifecycle methods