0

I have an async task that downloads a file from the web, it works fine when i preset the URL.

URL url = new URL("http://www.mylocalweather.org.uk/ribblehead/clientraw.txt")

However when i try and use a method defined in an other activity to return a URL it fails.

URL url = null;
url = splash.gps();

The method has worked fine in the past and when called from other activities, and the download function works fine when the URL is hardcoded into the async therefore it much be a problem with calling the method from an Async task, whats the work around for this?

this is the error that it comes up with

E/AndroidRuntime(16426): Caused by: java.lang.IllegalStateException: System services not available to Activities before onCreate()

Any help would be appreciated

many thanks

4

2 回答 2

0

其他 Activity 不存在(如错误说明,onCreate尚未调用),因此无法使用您正在使用的任何系统服务来获取 URL。

要么让 AsyncTask 检索 URL 本身,要么将信息从启动活动传递到托管 AsyncTask 的活动。

于 2013-10-30T20:42:38.473 回答
0

正如您的日志所说,您不能使用未创建Activity时的方法。Activity只需使用您的一些类并在那里定义您的方法,将您需要的参数传递给它。

于 2013-10-30T20:41:19.723 回答