I am developing an application which has many services. When I stop the intent service, all threads and service should be stopped but the UI is hung and the following errors
I Don't see a reason for using Intent service when there's need for the service to be stopped. But if you still think it has to be done then either make call to stopself() from onhandleIntent itself (which will again break the protocol), or you can call it from your activity(which is prone to stop queue processing which is pending).
i Would rather go with bounded services if i have to manage their whole lifecycle. Here's the reference::
http://developer.android.com/guide/topics/fundamentals/services.html
Profile your app - I found the cause of my similar problem that way.
Android Studio: Tools -> Android -> Android Device Monitor
Select your app and it the top (left) select:
Start method profiling
and after some time stop it the see the result.
Same problem also occured for me. But I am using SqLite. When I want to select List of my entity I forgot to add some important methods. When problem occured my code is following
public List<Blocked> getBlockeds() {
List<Blocked> blockeds = new ArrayList<>();
String[] allColumns = {"id", "phoneNumber"};
Cursor cursor = database.query("Blockeds", allColumns, null, null, null, null, "id desc");
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
Blocked blocked = new CursorToPojo().cursorToBlocked(cursor);
blockeds.add(blocked);
}
return blockeds;
}
When change code to following the problem solved.
public List<Blocked> getBlockeds() {
List<Blocked> blockeds = new ArrayList<>();
String[] allColumns = {"id", "phoneNumber"};
Cursor cursor = database.query("Blockeds", allColumns, null, null, null, null, "id desc");
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
Blocked blocked = new CursorToPojo().cursorToBlocked(cursor);
blockeds.add(blocked);
cursor.moveToNext();
}
cursor.close();
return blockeds;
}
I realised that when I did not use cursor.moveToNext
cursor never end and the preceding problem start.