【发布时间】:2012-01-06 00:37:05
【问题描述】:
我有我的第一堂课,它是一个加载屏幕。
public class Loading extends Activity {
public int switchscreensvalue = 0;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.loadinglayout);
new Loadsounds().execute(switchscreensvalue);
if (switchscreensvalue == 1)
{
Intent myIntent = new Intent(Loading.this, main.class);
startActivityForResult(myIntent, 0);
}
}
}
然后我有我的 asynctask 类。
public class Loadsounds extends AsyncTask<Integer, Void, Void> {
@Override
protected Void doInBackground(Integer... params) {
SoundManager.addSound(0, R.raw.rubber);
SoundManager.addSound(1, R.raw.metal);
SoundManager.addSound(2, R.raw.ice);
SoundManager.addSound(3, R.raw.wind);
SoundManager.addSound(4, R.raw.fire);
return null;
}
protected void onPostExecute(Integer...params){
int switchscreensvalue = 1;
}
}
我希望它启动异步任务,它将 5 个声音加载到音板中,完成后,将 int "switchscreensvalue" 更改为 1。然后,加载屏幕应该在 "switchscreensvalue" 时更改为主屏幕= 1. 但它不起作用。请任何人帮助我,只是第一次学习异步任务。事实上,Java 还是相当新的。我需要 asynctask 加载 5 个声音,然后将活动从加载更改为主要活动。
【问题讨论】:
标签: android android-activity android-asynctask