Android 屏幕方向慢?

发布于 2025-01-05 18:34:58 字数 740 浏览 0 评论 0原文

在我的 Android 应用程序中,我已将一些图像和数据从互联网加载到可扩展列表视图中。并且我已按如下方式处理方向更改。

@Override
public Object onRetainNonConfigurationInstance() {
    isOrentationChnged=true; 
    final Object data = arrGroupelements;
    return data;

}

在我的 onCreate()

     if(!isOrentationChnged){
    new LongRunning().execute();

}else{

      if((String[][])getLastNonConfigurationInstance()==null){
        new LongRunning().execute();
      }else{
    arrGroupelements= (String[][]) getLastNonConfigurationInstance();
    expList.setAdapter(new ExpAdapter(cont));
      }
}

isOrentationChnged=false;

LongRunning 中,它是一个 AsynacTask,它用于从互联网获取数据,并在方向更改后加载之前加载的数据(无需再次从互联网获取新数据),但速度非常慢。有没有其他方法有效地做到这一点?

In my Android application i have loaded some images and data from the internet into expandable list view.And i have handled orientation changes as follows.

@Override
public Object onRetainNonConfigurationInstance() {
    isOrentationChnged=true; 
    final Object data = arrGroupelements;
    return data;

}

in my onCreate()

     if(!isOrentationChnged){
    new LongRunning().execute();

}else{

      if((String[][])getLastNonConfigurationInstance()==null){
        new LongRunning().execute();
      }else{
    arrGroupelements= (String[][]) getLastNonConfigurationInstance();
    expList.setAdapter(new ExpAdapter(cont));
      }
}

isOrentationChnged=false;

LongRunning is a AsynacTask which have used to get the data from the internet and it loads previously loaded data after orientation change (without getting new data from the internet again) but it is very slow.Is there any alternative way to do this efficiently ??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小…楫夜泊 2025-01-12 18:34:58

最后,我找到了加速活动中方向变化的简单方法。

IDEA

每次方向更改都会重新创建活动,解决方案是您可以通过将以下代码行添加到应用程序清单文件上的活动标记来避免重新创建活动。

android:configChanges="orientation|keyboardHidden|screenSize"

上面的线避免了方向改变后的活动重新创建,这样您的活动将对方向变化更加敏感。

Finally i got simple way to speed up the orientation changes in an activity.

IDEA:

Each and every orientation change will recreate the activity the solution to this you can avoid the activity recreation by adding following code line to activity tag on your application's manifest file.

android:configChanges="orientation|keyboardHidden|screenSize"

above line avoid the activity recreation after orientation changes so your activity will be more responsive on orientation changes.

少女净妖师 2025-01-12 18:34:58

根据 David 的说法,除非将 isOrentationChnged 设置为静态,否则重新创建 Activity 时它将始终为 false。

无论如何,您实际上并不需要该变量,只需在 onCreate: 中执行此操作:

arrGroupelements = (String[][]) getLastNonConfigurationInstance();
if (null==arrGroupelements){
  new LongRunning().execute();
} else {     
  expList.setAdapter(new ExpAdapter(cont));
}

这样,如果正在重新创建活动,则将使用您的数据,否则将运行长时间运行的操作。

顺便说一句,我没有看到您在 Adapter 构造函数中使用 arrGroupelements 。

As per David unless isOrentationChnged is set to static it will always be false when your Activity is recreated.

You don't really need that variable anyway just do this in onCreate:

arrGroupelements = (String[][]) getLastNonConfigurationInstance();
if (null==arrGroupelements){
  new LongRunning().execute();
} else {     
  expList.setAdapter(new ExpAdapter(cont));
}

This way if the activity is being recreated then your data will be used, otherwise the longrunning operation will run.

By the way I don't see you using arrGroupelements in your Adapter constructor.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文