@Override protected void onDestroy() { realmDBManager.close(); if (EventBus.getDefault().isRegistered(this)) EventBus.getDefault().unregister(this); Runtime.getRuntime().gc(); super.onDestroy(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_matchday_detail); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); // Create the adapter that will return a fragment for each of the three // primary sections of the activity. mSectionsPagerAdapter = new MatchdayPagerAdapter(getSupportFragmentManager()); // Set up the ViewPager with the sections adapter. mViewPager = (ViewPager) findViewById(R.id.container); mViewPager.setAdapter(mSectionsPagerAdapter); TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs); // By using this method the tabs will be populated according to viewPager's count and // with the name from the pagerAdapter getPageTitle() tabLayout.setTabsFromPagerAdapter(mSectionsPagerAdapter); tabLayout.setupWithViewPager(mViewPager); realmDBManager = new ZappRealmDBManager(); tabLayout.setTabGravity(TabLayout.GRAVITY_FILL); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { createMatchday(); } }); RealmResults<Matchday> list = realmDBManager.list_all_matchdays(); setMatchday(new Matchday()); DateFormat df = new SimpleDateFormat("dd.MM.yyyy"); String date = df.format(Calendar.getInstance().getTime()); getMatchday().setDatum(date); EventBus.getDefault().register(this); }
@Override public int getCount() { return realmDBManager.list_all_members().size(); }
public MatchdayPagerAdapter(FragmentManager fm) { super(fm); // dbManager = ZappDBManager.getInstance(); realmDBManager = new ZappRealmDBManager(); memberlist = realmDBManager.list_all_members(); }
@Override public boolean onNavigateUp() { realmDBManager.close(); Runtime.getRuntime().gc(); return super.onNavigateUp(); }
private void createMatchday() { realmDBManager.insertRealmObject(getMatchday()); EventBus.getDefault().post(new SaveEvent()); }