android-service

Communication between Activity and Service

此生再无相见时 提交于 2019-11-26 00:47:10
问题 I am trying to make my own MusicPlayer for android. Where i came to a problem is running some things in background. Main activity manages GUI and up to now all the songs are playing. I wanted to separate GUI and music playing classes. I want to put music managing part in Service and leave other things as they are now. My problem is that i can\'t organize communication between Activity and Service as lot of communication is happening between them including moving objects in both directions. I

Determining the current foreground application from a background task or service

假装没事ソ 提交于 2019-11-25 23:58:33
问题 I wish to have one application that runs in the background, which knows when any of the built-in applications (messaging, contacts, etc) is running. So my questions are: How I should run my application in the background. How my background application can know what the application currently running in the foreground is. Responses from folks with experience would be greatly appreciated. 回答1: With regards to "2. How my background application can know what the application currently running in the

Android background music service

放肆的年华 提交于 2019-11-25 23:54:22
问题 I am developing an entertainment app in android. I want to play background music, and I want to use service for that. App have 3 activities and music must be played across all activities. Also, when activity is paused, music must PAUSE and stopped when destroyed. Can anyone tell me how to do this ? any links or examples ? Thank you. 回答1: Do it without service http://www.rbgrn.net/content/307-light-racer-20-days-61-64-completion If you are so serious about doing it with services using

Taking picture from camera without preview

你。 提交于 2019-11-25 23:33:52
问题 I am writing an Android 1.5 application which starts just after boot-up. This is a Service and should take a picture without preview. This app will log the light density in some areas whatever. I was able to take a picture but the picture was black. After researching for a long time, I came across a bug thread about it. If you don\'t generate a preview, the image will be black since Android camera needs preview to setup exposure and focus. I\'ve created a SurfaceView and the listener, but the

getApplication() vs. getApplicationContext()

末鹿安然 提交于 2019-11-25 23:19:31
问题 I couldn\'t find a satisfying answer to this, so here we go: what\'s the deal with Activity/Service.getApplication() and Context.getApplicationContext() ? In our application, both return the same object. In an ActivityTestCase however, mocking the application will make getApplication() come back with the mock, but getApplicationContext will still return a different context instance (one injected by Android). Is that a bug? Is it on purpose? I don\'t even understand the difference in the first

Android Fatal signal 11 (SIGSEGV) at 0x636f7d89 (code=1). How can it be tracked down?

心不动则不痛 提交于 2019-11-25 23:17:37
问题 I\'ve been reading the other posts on tracking down the reasons for getting a SIGSEGV in an Android app. I plan to scour my app for possible NullPointers related to Canvas use, but my SIGSEGV barfs up a different memory address each time. Plus I\'ve seen code=1 and code=2 . If the memory address was 0x00000000 , I\'d have a clue it is a NullPointer. The last one I got was a code=2 : A/libc(4969): Fatal signal 11 (SIGSEGV) at 0x42a637d9 (code=2) Any suggestions on how to track this down? I

Android - implementing startForeground for a service?

与世无争的帅哥 提交于 2019-11-25 22:49:52
问题 So I\'m not sure where/how to implement this method to make my service run in the foreground. Currently I start my service by the following in another activity: Intent i = new Intent(context, myService.class); context.startService(i); And then in myServices\' onCreate() I try the startForeground()...? Notification notification = new Notification(); startForeground(1, notification); So yeah I\'m a bit lost and unsure of how to implement this. 回答1: I'd start by completely filling in the

START_STICKY and START_NOT_STICKY

自作多情 提交于 2019-11-25 22:41:34
问题 What is the difference between START_STICKY and START_NOT_STICKY while implementing services in android? Could anyone point out to some standard examples.. ? 回答1: Both codes are only relevant when the phone runs out of memory and kills the service before it finishes executing. START_STICKY tells the OS to recreate the service after it has enough memory and call onStartCommand() again with a null intent. START_NOT_STICKY tells the OS to not bother recreating the service again. There is also a

android start activity from service

早过忘川 提交于 2019-11-25 22:33:32
问题 Android: public class LocationService extends Service { @Override public void onStart(Intent intent, int startId) { super.onStart(intent, startId); startActivity(new Intent(this, activity.class)); } } I launched this service from Activity In Activity if condition satisfies start startService(new Intent(WozzonActivity.this, LocationService.class)); from my LocationService mentioned above could not launch Activity , how can I get context of current running Activity in service class? 回答1: From

Service vs IntentService

柔情痞子 提交于 2019-11-25 22:31:20
问题 Can someone please show me an example of something that can be done with an IntentService that cannot be done with a Service (and vice-versa)? I also believe that an IntentService runs in a different thread and a Service does not. So, as far as I can see, starting a service within its own thread is like starting an IntentService . Is it not? I would appreciate if someone can help me with both of my questions. 回答1: Tejas Lagvankar wrote a nice post about this subject. Below are some key