【问题标题】:Will many import in a activity affect performance in android活动中的许多导入会影响android中的性能吗
【发布时间】:2012-01-01 06:25:49
【问题描述】:

活动/应用程序中的许多导入语句会影响 android 的性能吗?

示例情况1:

在一个活动/public class(我们称之为DialogHelper.java)中,我在这个单个 DialogHelper.java 中处理所有应用程序对话框,并且我在该活动中有多个导入语句,它会影响运行时性能还是有任何影响手机内存还是降低性能?

示例情况2:

而不是使用这个根本不需要导入的catch (Exception e)

try {   
String url = "data";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
activity.startActivity(i);
  } catch (Exception e) {
    //Exception here
  }

我用的是这个,需要导入android.content.ActivityNotFoundException;,哪个更好?

try {   
String url = "data";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
activity.startActivity(i);
  } catch (ActivityNotFoundException e) {
    //Exception here
  }

【问题讨论】:

    标签: android performance import


    【解决方案1】:

    实际上,除非您要导入数百个类,否则我怀疑您会看到性能下降。

    话虽如此,实际上你应该只导入你需要的东西。 IE。如果您需要该 ActivityNotFoundException 的特定内容,或者只想捕获该类型的异常,请务必使用它。但如果你不这样做,使用它的超类将会对性能造成非常小的负担。

    【讨论】:

      【解决方案2】:

      如果您正在执行与任何特定异常类型相关的任何代码,请使用此类特定异常(如 ActivityNotFoundException),否则直接使用一般异常。 在 Eclipse 中使用 cntrl + Shift + O 来导入类。

      如果不导入包、类,你就不能使用它们里面的东西......

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-12-05
        • 1970-01-01
        相关资源
        最近更新 更多