在我的应用程序中,我需要从互联网获取数据。所以我需要从闪屏和闪屏消失后在后台处理一个方法。
public class Splash_Screen extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash__screen);
ProgressBar p_bar=(ProgressBar)findViewById(R.id.progressBar1);
Thread thread=new Thread(new Runnable() {
@Override
public void run()
{
data_receiver receiver=data_receiver.getInstance();
receiver.access_parser();
}
});
thread.start();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent main_window=new Intent(com.burusoth1990.advertise.Splash_Screen.this,com.burusoth1990.advertise.MainActivity.class);
startActivity(main_window);
}
}, 5000);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_splash__screen, menu);
return true;
}
}
启动屏幕需要工作 5 秒,但在启动屏幕活动退出并打开新活动后,receiver.access_parser() 方法需要在后台工作。这是我的代码,但它会引发错误。