English 中文(简体)
静态无效
原标题:call static void
  • 时间:2011-10-26 13:19:01
  •  标签:
  • android

我如何称职?

public static void dial(Activity call) 
{ 
   Intent intent = new Intent(Intent.ACTION_DIAL); 
   call.startActivity(intent); 
} 

Obviously not with:

dial(); /*Something should be within the brackets*/
最佳回答

你可以放弃。 你们必须发出一个背景目标。

职能在哪里? 如果在某项活动或活动范围内进行,则只是将“这”作为参数。

If it s inside an BroadcastListener, or a Service, just change the parameter to Context and pass "this".

问题回答

You should try
ClassName.dial();

原因是静态方法属于阶级本身,而不是属于个别情况。 电话instance.dial()是合法的,但受到劝阻。

you should use your ClassName.StaticMethod.... to call a static method of a class

问题有什么例外?

If you ve got a class like

public class Test {
    public void nonStaticFct() {
        staticFct();
    }

    public static void staticFct() {
        //do something
    }
}

完全可行(即使你总是按职等称职)。 FctName( 试验.staticFct()

我在此猜测这个问题是缺失的论点。

根据http://www.oracle.com/technetwork/java/codeconventions-137265.html#587“rel=“nofollow”),我错了。 Java Code Conventions 您可以简单地使用一种分类方法,而不使用类别名称(即使似乎有错),因为我预计会暗中这样做。





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签