multithreading - Realm access from incorrect thread Android Error when it is the same thread -


i keep getting:

java.lang.illegalstateexception: realm access incorrect thread. realm objects can accessed on thread created. 

however thread has been interrupted time touches realm object, way of me fixing this?

    realmconfiguration config = new realmconfiguration.builder()             .name("customschedule.realm")             .schemaversion(42)             .build();     mrealm = realm.getinstance(config);      mdays = app.getmdays();      final handler handler = new handler();      t = new thread(new runnable() {         public void run() {             while(!thread.currentthread().isinterrupted()) {                 while (mdays.isempty()) {                 }                 thread.currentthread().interrupt();                 startactivity();                 handler.post(this);             }         }     });     t.start();      return rootview; } 

within startactivity section reference realm objects normal.

i changed thread to:

    final handler handler = new handler();      final thread t = new thread(new runnable() {         public void run() {             while(!thread.currentthread().isinterrupted()) {                 while (mdays.isempty()) {                 }                 handler.post(new runnable() {                     @override                     public void run() {                         startactivity();                     }                 });                 thread.currentthread().interrupt();             }         }     });     t.start(); 

and works.


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -