asynctask를 사용하여 Android를 시작하려고하는데 코드에 오류가 표시되지 않지만 URL을 표시하는 대신 응용 프로그램을 시작하면 화면에 "hello world"가 표시됩니다. .asynctask --android를 사용하여 URL을 시작하려고합니다.
//Starting the task. Pass an url as the parameter.
new PostTask().execute("http://www.google.com");
setContentView(R.layout.activity_main);
}
// The definition of our task class
private class PostTask extends AsyncTask<String, Integer, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected String doInBackground(String... params) {
String url=params[0];
for (int i = 0; i <= 100; i += 5) {
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
publishProgress(i);
}
return "All Done!";
}
@Override
protected void onProgressUpdate(Integer... values) {
super.onProgressUpdate(values);
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
}
}
편집 해 : 다음은 내 시도는 이 내 activity_main.xml 코드
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.project.unityapp.MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</RelativeLayout>
내 응용 프로그램 실행에 URL을 개방하지 않는 것입니다. 친절하게 도와주세요.
당신의 activity_main.xml 코드를 추가, 당신이 레이아웃 –
에 웹보기를 추가하지 않은 생각 그것은 귀하의 작업에 전달 된 URL로 아무것도하지 않는 것 같습니다 – gipsy
내 activity_main.xml 코드 – Francis