android - How to add a callback to an activity that's created in a fragment? -
i have fragment button calls following method when clicked/pressed: public void onclick() { intent intent = new intent(getactivity(), mynewactivity.class); startactivity(intent) } however, want pass callback method mynewactivity called inside activity's ondestroy method. need callback method call fragment's finish() method. i tried using static variables , worked seems bad design. what's best way this? if not through callback method, what's better approach? use startactivityforresult() proposed in comments. use below code: fragment: public class myfragment extends fragment { private static final int request_code = 1353; @override public view oncreateview(layoutinflater inflater, @nullable viewgroup container, @nullable bundle savedinstancestate) { view v = inflater.inflate(r.layout.fragment, container, false); v.findviewbyid(r.id.b...