When using overridePendingTransition, modifying UI views in the called activity is very slow

你。 提交于 2019-12-22 18:38:14

问题


a few days ago, I had a problem with updating an Action Bar menu icon based on the result of an AsyncTask: Updating Action Bar Menu Item due to AsyncTask result without delay

Now I realized that this problem is not at all related to an AsyncTask or an Action Bar. The problem occurs as well if I want to change a TextView or any other View.

After some time of trial and error I realized that the problem is caused by overridePendingTransition which I use in the Activity which calls the second Activity (where I want to change the icon):

First Activity (in an onItemClick method):

@Override
   public void onItemClick(View view, int position) {
   ...
   Intent intent = new Intent(getActivity(), SecondActivity.class);
   ...
   startActivityForResult(intent, anyValue);
   getActivity().overridePendingTransition(R.anim.slide_in_right, R.anim.no_animation);
}

The animation looks like that:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate android:fromXDelta="100%p" android:toXDelta="0"
            android:duration="@android:integer/config_shortAnimTime"/>
</set>

And this is how the AsyncTask (onPostExecute) of the second Activity looks like:

@Override
public void onPostExecute(String result) {
   super.onPostExecute(result);
   if (mMenu != null) {
      if (result.equals("no favorite")) {
      ...
      mMenu.findItem(R.id.action_favorite).setVisible(false);
      mMenu.findItem(R.id.action_no_favorite).setVisible(true);
   } else {
      ...
      mMenu.findItem(R.id.action_favorite).setVisible(true);
      mMenu.findItem(R.id.action_no_favorite).setVisible(false);
   }
}

As explained, instead of switching between two menu icons, you could also use one TextView and setting the text based on the result - the problem remains.

Do you know how I can change the animation without having this weird delay in my second Activity?


回答1:


Check your integer.xml file Make the value of config_shortAnimTime smaller according to your needs. Its in milliseconds. Prefer making it 1000 (1 sec).



来源:https://stackoverflow.com/questions/29318415/when-using-overridependingtransition-modifying-ui-views-in-the-called-activity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!