Найден обходной путь. Начиная с android 7.0, используйте AsyncTask в MainActivity.
MainActivity.kt:
class MainActivity: AppCompatActivity(view: View) {
...
fun startGameButtonClick() { // start the game
val layout: ConstraintLayout = findViewById(R.id.loading_layout)
Loading(layout).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR)
...
val intent = Intent(this, GameActivity::class.java)
startActivity(intent)
}
}
AsyncTask. java:
public class Loading extends AsyncTask<Void, Void, Void> {
private WeakReference<ConstraintLayout> layout;
public Loading(ConstraintLayout layout) {
this.layout = new WeakReference<>(layout);
}
@Override
protected void onPreExecute() {
layout.get().setVisibility(View.VISIBLE); // show load message
}
...
}