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();
}
}
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.