android-service

Start/Stop Service from Widget

*爱你&永不变心* 提交于 2019-12-04 23:56:54
问题 I want to start a service from inside the widget, I know that i can do it using PendingIntent like PendingIntent intent = PendingIntent.getService(context, 0, new Intent(context, MyService.class), Intent.FLAG_ACTIVITY_NEW_TASK); remoteViews.setOnClickPendingIntent(R.id.buttonWidgetStartService, intent); but the problem is that I've already used PendingIntent on that button for some other purpose. So, I tried starting the service using context.startService(new Intent(context, MyService.class))

BroadcastReceiver for WALLPAPER_CHANGED calls onReceive() multiple times : Android

橙三吉。 提交于 2019-12-04 22:50:59
I have a BroadcastReceiver and declared it like this: <receiver android:name="com.services.Receiver" android:enabled="true" android:exported="true" > <intent-filter android:priority="999" > <action android:name="android.intent.action.WALLPAPER_CHANGED" /> </intent-filter> </receiver> and the receiver is: @Override public void onReceive(final Context context, final Intent intent) { change_wallpepar.myPrefs = context.getSharedPreferences("myPrefs", Context.MODE_PRIVATE); new Handler().postDelayed(new Runnable() { @Override public void run() { Log.d("MAYUR", "<< wallpepar changed >>"); if (change

How to keep an IntentService running even when app is closed?

筅森魡賤 提交于 2019-12-04 22:38:25
In my Android app I start an IntentService from within an Activity by calling startService(new Intent(this, MyService.class)); And it works like a charm. I can move between Activies, press the Home button to switch to other apps... and it's still working. But if I remove my app from the recents screen, my service is stopped. How can I avoid this? In other words, how can I keep my service running even if my app is closed from recent apps? My service code is as follows: public class MyService extends IntentService { public MyService() { super("MyService"); } @Override protected void

Memory and CPU per process ANDROID

独自空忆成欢 提交于 2019-12-04 21:44:44
I'm developing an android application where in it, I want to get the running process or app list. I kinda found a way to do using activitymanager. but what I don't know is on how to get the processor and memory used per that process. does any one know how I can achieve this goal. the code to get the running processes is, I get all the running app processes from the above code. please help me to get the values for each an every process in the list. thank you. CPU load - you need to read the /proc/[pid]/stat (ref http://linux.die.net/man/5/proc ). Looking for utime & stime, they are the times

What will happen if I use try catch and finally for handler using runnable?

女生的网名这么多〃 提交于 2019-12-04 21:41:49
I use the code below for getting some work done everytime after some time interval, and using post delay in 'finally' clause and oustide of runnable. Here is the code. Runnable runnable = new Runnable() { @Override public void run() { try { // do somthing } catch (Exception e) { // TODO: handle exception } finally { handler.postDelayed(this, 60000); } } }; handler.postDelayed(runnable, 60000); handler.postDelayed(runnable, 60000); will run two times or a single time. it depends! first matter how the each try / catch / finally block completes normally or abruptly? the finally block "always ^ "

Android - How to get ETA from Google Maps App Intent? (Or Waze?)

ⅰ亾dé卋堺 提交于 2019-12-04 20:00:24
I'm working on android app witch will navigate to a place and do some stuff based on the ETA. I don't want to deal with navigation at all and this is why i use an Intent to open Google Maps App. Is there any way i can run a service to get the ETA from Google Maps App? Can i do it with Waze or any other navigation app? If not, what do you think about running a service wich will get ETA from Google Maps API every few minutes? Thanks for you time. Yirmi. 来源: https://stackoverflow.com/questions/31322856/android-how-to-get-eta-from-google-maps-app-intent-or-waze

RemoteViews for widget update exceeds max bitmap memory usage error

落花浮王杯 提交于 2019-12-04 20:00:17
问题 I have a widget that parses xml feed and display its title and image.In this widget I am using a service that periodically changes the contents(ie, title and image).For this I am using timer class.When we run this widget, some contents are displayed without any problem but after sometime it force closes and shows an error like "RemoteViews for widget update exceeds maximum bitmap memory usage(used:2465280 max:2304000) The total memory can't exceed that required to fill the device's screen

Android: how to save sensor data continuously while app is doing other works

元气小坏坏 提交于 2019-12-04 19:58:13
im new to android. i'm deveping an app to continuously save sensor's data and beside that takes photos. in fact i want to start saving accelerometer data in to a file while taking photos, or while screen is blacked out. i have reached to this point that my app saves sensor data as i touch a button, but it does it once. how can i make it to saves data continuously and without affecting other parts of my app to run? and i want it saves data while i'm taking photos in my app, when screen is blacked out, while i'm out of my app ( for example app is paused) plz hlp thnx. here is my code private

How to access instance of MediaBrowserServiceCompat service?

时光毁灭记忆、已成空白 提交于 2019-12-04 19:35:33
I'm surprisingly struggling to get hold of the instance of a service which is derived from MediaBrowserServiceCompat . For a typical service, to achieve that, a local binder is used class MyService extends MediaBrowserServiceCompat { class MyBinder extends Binder { public MyService getService() { return MyService.this; } private final MyBinder binder = new MyBinder(); @Override public IBinder onBind(Intent intent) { return binder; } public void doMagic() { // <-- How to call this from activity? // ... } } // At the activity, for example, this binder is retrieved through // `onServiceConnected(

java.lang.ClassCastException while running new `runnableThread` in `Service` Class

主宰稳场 提交于 2019-12-04 19:15:48
I have an application , contains a broadcastReceiver which listens to all new received SMS . If any new SMS received this BroadcastReceiver starts a background Service which runs GPS and return the coordinates , this coordinate retrieving needs a new thread to be run , in the Service class there is no getApplicationContext() so I used 'getContentBase()' for starting the new thread this is the code ((Activity)getBaseContext()).runOnUiThread(new Runnable() { ((Activity)getBaseContext()).runOnUiThread(new Runnable() { @Override public void run() { // TODO Auto-generated method stub