android - Best practice when using fragments in activities? -
i have fragment opens various dialogs , starts async tasks. use listener pattern info dialogs or tasks.
to open dialog following:
public void selectdialog() { mydialog dialog = mydialog .newinstance(); dialog.setfragment(this); dialog.show(getfragmentmanager(), "selectdialog"); }
and task:
public void dotask() { mytask mytask = new mytask(getactivity(), this, criteria); mytask .execute((void)null); }
the reason i'm passing activity , fragment task because task uses sqlite db , helper class needs context (ie activity) , opens alertdialog. fragment casting listener.
with above implementation, can use dialogs , tasks within fragments now.
is above correct way open dialogs , start tasks fragments? or should activity listener , pass info fragment?
Comments
Post a Comment