나는 서비스 클래스와 활동이있는 앱을 작성했습니다. 연락처 데이터베이스의 변경 사항을 수신하는 24X7 백그라운드에서 앱을 실행하는 방법
내가이public class RecycleBinActivity extends Activity {
/** Called when the activity is first created. */
Uri cpath=null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
cpath=ContactsContract.Contacts.CONTENT_URI;
this.getApplicationContext().getContentResolver().registerContentObserver(cpath, true, observer);
}
private class MyContentObserver extends ContentObserver {
public MyContentObserver() {
super(null);
}
@Override
public void onChange(boolean selfChange) {
super.onChange(selfChange);
Intent i=new Intent(RecycleBinActivity.this.getApplicationContext(),DeleteService.class);
startService(i);
}
@Override
public boolean deliverSelfNotifications()
{
super.deliverSelfNotifications();
return true;
}
}
MyContentObserver observer=new MyContentObserver();
}
같은 활동에서 서비스를 시작하고 내 서비스 구현은 처음 에 대한 알림을 표시 연락처를 내가이 응용 프로그램을 실행할 때
public class DeleteService extends Service {
private final IBinder mBinder = new LocalBinder();
Notification nf;
NotificationManager nfm;
Uri cpath,lookupuri;
String lookupkey;
Cursor cur;
Runnable refresher;
ContentResolver cr;
@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return mBinder;
}
@Override
public void onCreate() {
cpath=ContactsContract.Contacts.CONTENT_URI;
// some action
nfm=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
int NOTIFICATION_ID = 1;
Intent intent = new Intent();
PendingIntent pi = PendingIntent.getActivity(DeleteService.this, 1, intent, 0);
nf=new Notification(R.drawable.ic_launcher,"Contact Database changed",System.currentTimeMillis());
nf.setLatestEventInfo(getApplicationContext(), "Delete Event", "contact name", pi);
nf.flags = nf.flags |
Notification.FLAG_ONGOING_EVENT;
startForeground(NOTIFICATION_ID, nf);
}
@Override
public void onDestroy() {
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// TODO Launch a background thread to do processing.
super.onStartCommand(intent, flags, startId);
return Service.START_STICKY;
}
public class LocalBinder extends Binder {
DeleteService getService() {
return DeleteService.this;
}
}
}
아래와 같이 수정한다 내가 몇 초 안에 수정을했다면 아무 것도 도와 줄 수 없다. 왜 아무도 도와주지 못한다.
부팅을 시작할 수있는 기능이있는 전경 서비스는 다소 24X7 서비스입니다. –