java - Android - StartActivityForResult on finish() method freezes UI -


i have following situation:

  1. activity starts activity b, using startactivityforresult
  2. activity b returns arraylist of strings activity using on finish().

here code example of activity b does:

arraylist<string> urls = new arraylist<>(); urls.add("some string");  intent intent = new intent(); intent.putstringarraylistextra(key, urls); setresult(activity.result_ok, intent); finish(); 

then activity receive data in onactivityresult(...)

the issue have when user taps done button , activity b's code example executes, activity b freezes 3 seconds (when have 2 strings in arraylist). more strings have in arraylist longer freezes. have more or less determined finish() causes ui thread freeze.

is there way call finish() without freezing activity b? if not, why happening?

edit: here full example:

   /**     * background task     */    private class gatherurlstask extends asynctask<arraylist<pictureentry>, integer, intent> {         @override        protected void onpreexecute() {            progressbar.setvisibility(view.visible);            bt_done.setvisibility(view.gone);            fab_add_picture.setvisibility(view.gone);        }         @safevarargs        @override        protected final intent doinbackground(arraylist<pictureentry>... params) {            arraylist<string> imagepaths = new arraylist<>();             (pictureentry pictureentry : params[0]) {                if (pictureentry.isselected()) {                    imagepaths.add(pictureentry.getpath());                }            }             if (imagepaths.size() == 0) {                toast.maketext(getapplicationcontext(), r.string.please_select_atleast_one_image, toast.length_long).show();                return null;            } else {                intent intent = new intent();                intent.putstringarraylistextra(selected_images_key, imagepaths);                return intent;            }        }         @override        protected void onpostexecute(intent intent) {            setresult(activity.result_ok, intent);            finish();        }    } 

however can remove asynctask since did not have effect on performance.

i don't know cause of that, prevent ui getting freezed, use asynctask , in onpostexcecute call finish()


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

filehandler - java open files not cleaned, even when the process is killed -

gridview - Yii2 DataPorivider $totalSum for a column -