android 异步任务

发布于 2025-01-04 17:02:11 字数 124 浏览 0 评论 0原文

在 Android 中定义 ASyncTask 及其关联方法时,会出现 3 个点,例如 protected Long doInBackground(URL... urls)

这些点是什么意思?

When defining an ASyncTask and it associated methods in Android there are 3 dots that appear, eg protected Long doInBackground(URL... urls)

What do the dots mean?

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

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

发布评论

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

评论(3

も让我眼熟你 2025-01-11 17:02:11

这不完全是一回事。考虑以下示例

示例 1:

public String concatenateStrings(String... strings){
  StringBuffer sb = new StringBuffer();
  for( int i = 0; i < strings.length; i++ )
    sb.append( strings[i] );

  return sb.toString();
}

示例 2:

public String concatenateStrings2(String[] strings){
  StringBuffer sb = new StringBuffer();
  for( int i = 0; i < strings.length; i++ )
    sb.append( strings[i] );

  return sb.toString();
}

它们几乎相同,对吗?错了,叫他们区别就大了。第一个示例允许添加未定义数量的字符串。

示例 1:

concantenateStrings("hello", "World", " I ", " can ", " add ", " so ", " many strings here" );

示例 2:

Strings[] myStrings = new Strings[7];
myStrings[0] = "Hello";
myStrings[1] = "world";
myStrings[2] = " I ";
...
myStrings[6] = " many strings here";
concatenateStrings2( myStrings );

It's not entirely the same thing. Consider the following examples

Example 1:

public String concatenateStrings(String... strings){
  StringBuffer sb = new StringBuffer();
  for( int i = 0; i < strings.length; i++ )
    sb.append( strings[i] );

  return sb.toString();
}

Example 2:

public String concatenateStrings2(String[] strings){
  StringBuffer sb = new StringBuffer();
  for( int i = 0; i < strings.length; i++ )
    sb.append( strings[i] );

  return sb.toString();
}

They're allmost identical, right? Wrong, calling them is the big difference. The first example allows for an undefined number of strings to be added.

Example 1:

concantenateStrings("hello", "World", " I ", " can ", " add ", " so ", " many strings here" );

Example 2:

Strings[] myStrings = new Strings[7];
myStrings[0] = "Hello";
myStrings[1] = "world";
myStrings[2] = " I ";
...
myStrings[6] = " many strings here";
concatenateStrings2( myStrings );
季末如歌 2025-01-11 17:02:11

这不是 AsynTask 特定的或 Android 特定的。将可变长度的参数传递给方法是 Java 的一项功能。

看看:
如何创建接受可变数量参数的 Java 方法?

This is not AsynTask specific or Android specific for that matter. It's a Java feature to pass variable length of parameters to a method.

Have a look at:
How to create Java method that accepts variable number of arguments?

无声静候 2025-01-11 17:02:11

它是java的概念。它看起来像数组。 (并且您对它的处理主要就像在数组上处理一样)。但是,在某些方面有所不同。

在 Android 中,您经常会遇到这种情况,例如,当您使用视图动画属性动画进行布局时。

It java concept. It looks like array. (and you process it mostly like you process on array). But, it 's different in some points.

You will meet this commonly in android, for example when you use view animation or property animation for layout.

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