There are two activities which are main and reding. When I click the open book in main activity, a loading fragment should be appear on screen until reading activity loaded completely.
In activity main, activity reading open click event:
@Override
public void onClick(View v) {
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction()
// fragment fade in enough
.setCustomAnimations(R.anim.fade_in, 0, 0, 0)
// main_root in activity main.
.add(R.id.main_root, new BookLoadingFragment(), "BookLoaderFragment")
.addToBackStack("BookLoaderFragmentStackTag")
.commit();
fragmentManager.executePendingTransactions();
Intent intent = new Intent(context, ReadBookActivity.class);
context.startActivity(intent);
}
So by the above code, loading fragment don't appear until reading activity opened completely (It appear without setCustomAnimations()). I've tried creating new thread or async task for fragment but there was an error creating fragmet not allowed outside of ui thread. Also I've to create fragment in main activity because reading activity has many other fragments attached it with onActivityCreated().