whether the Android FragmentTransaction.replace() is thread safety?

615 views Asked by At

I remember only the UI Thread can modify the View of the Activity, no-UI Thread can not modify the view. So whether the method "replace()" which you will find in the code is thread safety ? if the code is right, why that method can do that ?(Thanks)

This is code:

public class SelectBookActivity extends Activity implements BookListFragment.Callbacks { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // inflate a ListFragment and a container setContentView(R.layout.activity_book_twopane); } // the method in the interface @Override public void onItemSelected(Integer id) { Bundle arguments = new Bundle(); arguments.putInt(BookDetailFragment.ITEM_ID, id); BookDetailFragment fragment = new BookDetailFragment(); fragment.setArguments(arguments); getFragmentManager().beginTransaction() .*replace*(R.id.book_detail_container, fragment) .commit(); } }

1

There are 1 answers

0
Michael On

the method commit() Schedules a commit of this transaction. The commit does not happen immediately; it will be scheduled as work on the main thread to be done the next time that thread is ready.