我在服务类中收到以下错误。这是什么问题?
错误:(17,4)错误:NotificationService不是抽象的,并且不会覆盖服务中的抽象方法onBind(Intent)
这是我的代码:
package works.viswajith.birthdayreminder;
import android.app.NotificationManager;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.DatabaseUtils;
import android.support.v4.app.NotificationCompat;
import java.util.Calendar;
/**
* Created by Viswajith on 6/17/2015.
*/
public class NotificationService extends Service {
DBHelper db;
private Cursor cur;
private Calendar cal;
private int d,m,y;
private String[] temp;
private NotificationManager nm;
int i=0;
@Override
public void onCreate() {
super.onCreate();
db=new DBHelper(getApplicationContext());
cur=db.getDetails();
cal= Calendar.getInstance();
d=cal.get(Calendar.DAY_OF_MONTH);
m=cal.get(Calendar.MONTH);
y=cal.get(Calendar.YEAR);
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
for(i=0;i<db.getCount();i++)
{
temp=cur.getString(2).split("/");
if(Integer.parseInt(temp[0])==d)
{
NotificationCompat.Builder mbuilder=new NotificationCompat.Builder(this);
mbuilder.setSmallIcon(R.drawable.happy);
mbuilder.setContentTitle("Happy B'day "+cur.getString(0));
mbuilder.setContentText("Today is "+cur.getString(0)+"'s B'day , Wish him ..");
nm=(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(100,mbuilder.build());
}
cur.moveToNext();
}
return super.onStartCommand(intent, flags, startId);
}
}
答案 0 :(得分:3)
错误已向您解释清楚:您必须覆盖onBind()
或以其他方式使您的服务抽象化。
这是你应该怎么做的:
@Override
public IBinder onBind(Intent intent) {
// Implement your logic here.
}
答案 1 :(得分:0)
它告诉你你到底需要做什么......
因为您正在扩展服务,所以您需要覆盖onBind
方法。
将以下内容添加到您的课程中:
@Override
public IBinder onBind(Intent intent) {
}
当android绑定到您的服务时,将调用此方法。