I'm deleting Sq-lite database file from android application package on log out button and at that time also want to stop the services which is run in the background but facing error of FATAL EXCEPTION: IntentService[helloservice].
Here is my Logout button code
imgBtn_LogOut.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
stopService(new Intent(Filter_Screen.this, MyService.class));
stopService(new Intent(Filter_Screen.this, DownLodProfileSrvice.class));
Log.e("Service ", " Stop !!!");
editor.putBoolean("LOG_EVENT", false);
editor.commit();
actvitiyContext.deleteDatabase(dbhelper.DATABASE_NAME);
Log.e("Database", " Deleted Completeley !!!");
Intent i = new Intent(Filter_Screen.this, Login_Screen.class);
startActivity(i);
finish();
}
});
Error Log
01-04 10:19:06.415 19739-20562/com.example.tazeen.classnkk E/SQLiteLog﹕ (1032) statement aborts at 23: [update ActivityObjectList set DownLoad_Status='1' where imageaudioPath ='560e9df1-a404-47e8-a98b-3d77f0374213.jpg']
01-04 10:19:06.417 19739-20562/com.example.tazeen.classnkk E/AndroidRuntime﹕ FATAL EXCEPTION: IntentService[helloservice]
Process: com.example.tazeen.classnkk, PID: 19739
android.database.sqlite.SQLiteReadOnlyDatabaseException: attempt to write a readonly database (code 1032)
at android.database.sqlite.SQLiteConnection.nativeExecuteForChangedRowCount(Native Method)
at android.database.sqlite.SQLiteConnection.executeForChangedRowCount(SQLiteConnection.java:734)
at android.database.sqlite.SQLiteSession.executeForChangedRowCount(SQLiteSession.java:754)
at android.database.sqlite.SQLiteStatement.executeUpdateDelete(SQLiteStatement.java:64)
at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1676)
at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1605)
at com.example.tazeen.classnkk.MyService.Loaddata(MyService.java:114)
at com.example.tazeen.classnkk.MyService.onHandleIntent(MyService.java:80)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.os.HandlerThread.run(HandlerThread.java:61)
This is my service task
public void Loaddata() {
db = myDBHelper.getWritableDatabase();
Cursor cursor = db.rawQuery("select * from ActivityObjectList", null);
if (cursor.moveToFirst())
{
do {
imageName = cursor.getString(cursor.getColumnIndex("imageaudioPath"));
str_DownLoadUrl = cursor.getString(cursor.getColumnIndex("DownLoad_Status"));
str_ActiveImageStatus = cursor.getString(cursor.getColumnIndex("ActiveStatus"));
if(str_ActiveImageStatus.equals("1"))
{
if( str_DownLoadUrl.equals("0") && imageName.endsWith(mp3_Pattern))
{
String fileUrl = namespace + "/DownloadFile/FilePathMobile/ATTACHMENT/FileName/"+imageName;
newFolder = new File(Environment.getExternalStorageDirectory().getPath() + File.separator + "classnkk_audio");
download_PngFileImgLoader(fileUrl, newFolder , imageName);
db = myDBHelper.getWritableDatabase();
db.execSQL("update ActivityObjectList set DownLoad_Status='1' where imageaudioPath ='" + imageName + "'");
}
if( str_DownLoadUrl.equals("0") )
{
if(imageName.endsWith(png_Pattern) || imageName.endsWith(jpg_pattern) || imageName.endsWith(bmp_pattern) || imageName.endsWith(gif_pattern) || imageName.endsWith(jpeg_pattern))
{
String fileUrl = namespace + "/DownloadFile/FilePathMobile/ATTACHMENT/FileName/"+imageName;
newFolder = new File(Environment.getExternalStorageDirectory().getPath() + File.separator + "classnkk_images");
download_PngFileImgLoader(fileUrl, newFolder, imageName);
db = myDBHelper.getWritableDatabase();
db.execSQL("update ActivityObjectList set DownLoad_Status='1' where imageaudioPath ='" + imageName + "'");
}
}
}
}
while (cursor.moveToNext());
}
cursor.close();
}