Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android access activity method inside service

How to call an Activity's non-static method from inside a service onStart()?

like image 464
Mahmoud Abou-Eita Avatar asked May 28 '12 11:05

Mahmoud Abou-Eita


People also ask

How can we call a method in service from an activity in Android?

You can call startService(intent) and bindService(mIntent, mConnection, BIND_AUTO_CREATE) in any order. Binding and Starting a service are two independent things.

How do I open background activity?

Intent intent = new Intent(myActivity. this, myActivity. class); PendingIntent contentIntent = PendingIntent. getActivity(this, REQUEST_CODE, intent, 0); notification.

How activities are different from the services in Android?

Services are a unique component in Android that allows an application to run in the background to execute long-running operation activities, on the other hand, an activity, like a window or a frame in Java, represents a single screen with a user interface.


1 Answers

How to call an Activity's non-static method from inside a service onStart()?

You can't.

However, there are many ways to have a service communicate with a running activity, and I outline some of them here: How can I update information in an Android Activity from a background Service

like image 146
CommonsWare Avatar answered Sep 30 '22 19:09

CommonsWare