Skip to content

Instantly share code, notes, and snippets.

@cthulhuplush
Created February 20, 2017 09:22
Show Gist options
  • Save cthulhuplush/fda732864bf3b807b9f5a6d53c9d678e to your computer and use it in GitHub Desktop.
Save cthulhuplush/fda732864bf3b807b9f5a6d53c9d678e to your computer and use it in GitHub Desktop.
public class MainActivity extends AppCompatActivity
{
private static final long MOVE_DEFAULT_TIME = 1000;
private static final long FADE_DEFAULT_TIME = 300;
private FragmentManager mFragmentManager;
private Handler mDelayedTransactionHandler = new Handler();
private Runnable mRunnable = this::performTransition;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
mFragmentManager = getSupportFragmentManager();
loadInitialFragment();
mDelayedTransactionHandler.postDelayed(mRunnable, 1000);
}
private void loadInitialFragment()
{
Fragment initialFragment = Fragment1.newInstance();
FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.fragment_container, initialFragment);
fragmentTransaction.commit();
}
private void performTransition()
{
// more on this later
}
@Override
protected void onDestroy()
{
super.onDestroy();
mDelayedTransactionHandler.removeCallbacks(mRunnable);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment