android - How to finish an activity just before starting a Fragment? -


i have activity contains button , starts fragment when clicked.but need finish current activity when starting fragment.how possible?i tried calling finish() after starting fragment.but not working.

android.app.fragmentmanager fm = getfragmentmanager(); detailfragment dialog_fragment = new detailfragment("events",name,id); dialog_fragment.show(fm, "detailscreen"); finish(); 

call getactivity().finish(); fragment finish activity.

however, careful. getactivity() null. in case, don't call finish(). activity destroyed.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -