I am dealing with this issue on Android :
Realm access from incorrect thread. Realm objects can only be accessed on the thread they where created.
I want to use Realm in my RemoteViewsFactory with
public class RemoteViewsX implements RemoteViewsFactory {
public RemoteViews getViewAt(int paramInt) {
if (this.results != null && this.results.size() != 0 && this.results.get(paramInt) != null) {
//FAILED HERE
}
}
... This call failed! Why ?
I fetch my data like this in my class:
public void onDataSetChanged() {
Realm realm = Realm.getInstance(RemoteViewsX.this.ctx);
this.results = realm.where(Model.class).findAll();
}
I called my remoteFactory like this :
public class ScrollWidgetService extends RemoteViewsService {
@Override
public RemoteViewsFactory onGetViewFactory(Intent intent) {
return new RemoteViewsX (getApplicationContext());
}
}
Any idea ?