I have written a service To delete data from a table when data inputed into it(tblTest) as given below
public class service_helper extends Service {
private DatabaseAdapter dbAdapter;
@Override
public IBinder onBind(Intent arg0) {
return null;
}
@Override
public void onCreate() {
super.onCreate();
Toast.makeText(this,"Service created ...", Toast.LENGTH_LONG).show();
dbAdapter = new DatabaseAdapter(this);
dbAdapter.open();
String sqlTransaction = "Select test from tblTest where test > ?";
dbAdapter = new DatabaseAdapter(this); dbAdapter.open();
Cursor cursorTransaction = dbAdapter.ExecuteRawQuery(sqlTransaction, "-1");
for (int i = 0; i < cursorTransaction.getCount(); i++) {
String sql = "DELETE FROM tblTest WHERE test=" + i + " ";
dbAdapter.ExecuteQuery(sql);
}
}
@Override
public void onDestroy() {
super.onDestroy();
Toast.makeText(this, "Service destroyed ...", Toast.LENGTH_LONG).show();
}
}
I have Started the service in the on create of main activity as given below
startService(new Intent(this, service_helper.class));
The problem is that I can't do anything in my applicaion because of the service got stated.I cant navigate from my main form.Is it the Right way to implement Service ?
Will any one help me