I'm working on a jar file that gets included in other applications, and it has to be very robust.
in the jar, i have an object, say SomeView
, which takes in an Android Context, tries to create a Handler
object, and will touch views, so it needs to be initialized from the main thread. How can i guarantee 100% that they won't initialize my SomeView
in the wrong thread?
such as:
public class SomeView {
Handler mHandler;
public SomeView(Context context) {
mHandler = new Handler();
}
}
i.e. will if (Thread.currentThread().getId() != 1) failSafely();
in the constructor work?