我在将主页链接到其他页面时遇到问题。我已经搜索并运行了这里已经问过的所有q& a,但是有错误。 有人可以帮助我..这是非常有用的.. tq
public class BackgroundTask extends AsyncTask<String,Void,String>
{
AlertDialog alertDialog;
ProgressDialog progressDialog;
Context ctx;
BackgroundTask(Context ctx)
{
this.ctx=ctx;
}
@Override
protected void onPreExecute()
{
alertDialog= new AlertDialog.Builder(ctx).create();
alertDialog.setTitle("Login Information...");
}
@Override
protected String doInBackground(String... params)
{
String login_url="http://10.0.2.2/webapp/login.php";
String method = params[0];
}
@Override
protected void onProgressUpdate (Void... values)
{
super.onProgressUpdate(values);
}
这是......
@Override
protected void onPostExecute (String result)
{
alertDialog.setMessage(result);
alertDialog.show();
//Want to go new activity page`enter code here`
}
}
已经尝试过但无法正常工作。
Intent intent = new Intent(MyAsyncTaskActivity.this, NextActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplicationContext().startActivity(intent);
答案 0 :(得分:1)
Intent intent = new Intent(ctx, NextActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //optional
ctx.startActivity(intent);
答案 1 :(得分:0)
你应该遵循这个结构
public class MyAsyncTaskActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_screen);
....
new BackgroundTask().execute();
....
}
private class BackgroundTask extends AsyncTask {
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected Void doInBackground(Void... arg0) {
// ….
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
Intent intent = new Intent(MyAsyncTaskActivity.this,NextActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //optional
startActivity(intent);
finish();
}
}
}
希望这个帮助