Injecting a repository into a Service in Android using Hilt

From the documentation on how we Inject dependencies into Android classes, we can learn the following: Hilt can provide dependencies to other Android classes that have the @AndroidEntryPoint annotation. Hilt currently supports the following Android classes: Application (by using @HiltAndroidApp) ViewModel (by using @HiltViewModel) Activity Fragment View Service BroadcastReceiver So when you subclass any of … Read more

How to start Service using Alarm Manager in Android?

This is what I have used, for starting service after 30 seconds from current time, Intent intent = new Intent(DashboardScreen.this, ServiceClass.class); PendingIntent pintent = PendingIntent.getService(DashboardScreen.this, 0, intent, 0); AlarmManager alarm = (AlarmManager)getSystemService(Context.ALARM_SERVICE); alarm.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 30*1000, pintent); Try it, and let me know what happen… EDIT: In your manifest.xml file <service android:enabled=”true” android:name=”.ServiceClass” />

Android background music service

Do it without service https://web.archive.org/web/20181116173307/http://www.rbgrn.net/content/307-light-racer-20-days-61-64-completion If you are so serious about doing it with services using mediaplayer Intent svc=new Intent(this, BackgroundSoundService.class); startService(svc); public class BackgroundSoundService extends Service { private static final String TAG = null; MediaPlayer player; public IBinder onBind(Intent arg0) { return null; } @Override public void onCreate() { super.onCreate(); player = MediaPlayer.create(this, R.raw.idil); … Read more

Using Google Play Services LocationClient in background service

Full source code for a background service available here: https://gist.github.com/blackcj/20efe2ac885c7297a676 Try adding the super call to your onStartCommand. /** * Keeps the service running even after the app is closed. * */ public int onStartCommand (Intent intent, int flags, int startId) { super.onStartCommand(intent, flags, startId); setUpLocationClientIfNeeded(); if(!mLocationClient.isConnected() || !mLocationClient.isConnecting()) { mLocationClient.connect(); } return START_STICKY; }

Android application as a service without activity

Sure! No reason you cannot have an application with only a service. …and no need to get into AIDL unless you want to. The problem is, how to make the application run. When you create an application with an Activity, you add an Intent filter, in the manifest, that makes the activity startable from the … Read more

Unable to start service Intent: not found

Solved I deleted the period in the beginning of the package name in the manifest and it worked, in another words: This doesn’t work: .yourPackage.YourClass But this does work: yourPackage.YourClass And in the main: Intent intent = new Intent(this, MoodyService.class); this.startService(intent); But it goes against what is written in the documentation: android:name The name of … Read more