Reputation: 1648
I am wondering the difference between Service Class and Class without Activity. // My Class to play Media
Class MyMediaPlayer{
private Context mContext;
//Contructor
public MyMediaPlayer(Context ct)
{
mContext = ct;
}
public void onCreate() {....code...}
public void onStart() {....code...}
public void onDestroy() {....code....}
}
The way of using is very similar to Service Class for Media.
Thanks you very much
Upvotes: 0
Views: 403
Reputation: 1966
A service is a class that is designed to do some long running operation, or run in the background when the application's activity is paused or stopped.
http://developer.android.com/reference/android/app/Service.html
The phone app has an activity, which has a very well defined life cycle. If you need to do work in the bg, or at a time that the activity no longer has the phone's focus, you can make use of a service. A class that is neither an activity or a service can serve any number of purposes.
It looks like the MyMediaPlayer class you have defined has the methods defined by activity, but does not implement activity. If the class defines some action that needs to be run in the foreground, have it extend 'Activity' so those methods can be called by android when needed.
Upvotes: 2