I'm starting an IntentService
with the following method:
private void startMyService(Data data) {
Intent intent = new Intent(this, MyService.class);
intent.putExtra(KEY_DATA, data.toJson());
startService(intent);
}
The Data
class:
public class Data extends ArrayList<MyObject> {
public Data() {
super();
}
public Data(Collection<MyObject> myObjects) {
super(myObjects);
}
public String toJson() {
return new Gson().toJson(this);
}
public static Data fromJson(String jsonString) {
return new Gson().fromJson(jsonString, Data.class);
}
}
The relevant part of the IntentService
:
public class MyService extends IntentService {
private Data data;
public MyService() {
super("myServiceName");
}
@Override
public void onCreate() {
super.onCreate();
// this gets called properly
Log.d("myTag", "Service onCreate()");
}
@Override
protected void onHandleIntent(Intent intent) {
// this is not called in case of the bigger dataset
Log.d("myTag", "Service onHandleIntent()");
String dataJson = intent.getStringExtra(KEY_DATA);
data = Data.fromJson(dataJson);
// doing stuff with data
}
}
I have 2 test scenarios:
- Data holds 2000 objects
- Data holds 4000 objects
With 2000 objects, the Service
runs flawlessly.
With 4000 objects, the onCreate()
method of the Service
is called and that's it... onHandleIntent()
is not called. The app just throws an ANR after a while.
I've tested with both Log.d()
calls and breakpoints on the first line of onHandleIntent()
, it is not called at all when Data
holds 4000 objects.
TransactionTooLargeException
is not thrown.
I get no Exception
s thrown at all, no idea what's wrong.
What could be the cause of this behaviour?