How to get back to the activity and execute a method? [duplicate]

1

I have a Profile.class activity and it shows my photos, when clicking on it, opens a fragmentDialog showing the photo in slideshow ... but when deleting the photo, I need to go back to my profile and update my photos, running photos (myID);

How to do this, if possible?!

SlideshowDialogFragment.class

private void delete_photo(final String idPhoto){
        pDialog.setMessage(getResources().getText(R.string.wait));
        showDialog();
        String tag = "deletePhoto";
        pDialog.setMessage(getResources().getText(R.string.wait));
        showDialog();
        StringRequest req = new StringRequest(Request.Method.POST,
                Config.DEL, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                hideDialog();
                try {
                    JSONObject jObj = new JSONObject(response);
                    boolean error = jObj.getBoolean("error");
                    if (!error) {
                        new Alert().MessageSuccess(getActivity(), view,
                                getText(R.string.delete_photo_success).toString());
                        // Voltar para meu Perfil.class e executar fotos(myID);


                    } else {
                        new Alert().MessageError(getActivity(), view,
                                getText(R.string.delete_photo_error).toString());
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                new Alert().MessageError(getActivity(), view,
                        getText(R.string.error_connection).toString());
                hideDialog();
            }
        }) {
            @Override
            protected Map<String, String> getParams() {
                Map<String, String> params = new HashMap<String, String>();
                params.put("me", myID);
                params.put("id", idPhoto);
                params.put("token", code);
                return params;
            }
        };
        CustomApplication.getInstance().addToRequestQueue(req, tag);
    }
    
asked by anonymous 29.09.2016 / 21:07

1 answer

3

Walkthrough:

1 - Create an interface by putting a void resposta(); method inside it 2 - Make the activity implement this interface and program within the implemented method to update the list. 3 - Within the fragment, declare a variable of the interface type.
4 - At the time of creating the fragment, send this (a activity) and insert this this into the interface variable that is in the fragment. 5 - When you finish the fragment exclusion method (or in the last line of the exclusion method), call interface.response ();

This final command will call the resposta(); method of the activity (pq inside the interface will contain the value of this activity).

    
29.09.2016 / 21:47