概述
从活动A跳到活动B,如果用putExtra存入key-value值,在B中Bundle bun = this.getIntent.getString()方法会报错
从login到welcome报错,去掉welcome的Bundle就能通过
主要是77-85行
public class login extends Activity{
private static String url_create_product = "http://100.71.128.80/myproduct/denglu.php";
private static final String TAG_SUCCESS = "success";
private ProgressDialog pDialog;
JSONParser jsonParser = new JSONParser();
EditText usern,userp;
Button zhuce,denglu;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.log_in);
usern=(EditText)findViewById(R.id.usern);
userp=(EditText)findViewById(R.id.userp);
zhuce=(Button)findViewById(R.id.zhuce);
denglu=(Button)findViewById(R.id.denglu);
zhuce.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent it = new Intent();
it.setClass(getApplicationContext(), zhuce.class);
startActivity(it);
}
});
denglu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(usern.length()!=0&&userp.length()!=0)
new LogUser().execute();
else Toast.makeText(getApplicationContext(), "empty", Toast.LENGTH_SHORT).show();
}
});
}
class LogUser extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
pDialog = new ProgressDialog(login.this);
pDialog.setMessage("Loging..");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
@Override
protected String doInBackground(String... args) {
// TODO Auto-generated method stub
String name = usern.getText().toString();
String passwd = userp.getText().toString();
List<NameValuePair> para = new ArrayList<NameValuePair>();
para.add(new BasicNameValuePair("name", name));
para.add(new BasicNameValuePair("passwd", passwd));
// getting JSON Object
// Note that create product url accepts POST method
JSONObject json = jsonParser.makeHttpRequest(url_create_product,
"POST", para);
// check log cat fro response
Log.d("Create Response", json.toString());
// check for success tag
try{
int success = json.getInt(TAG_SUCCESS);
if(success == 1) {
String info = json.getString("product");
Intent it= new Intent();
it.setClass(getApplicationContext(),welcome.class);
Bundle bundle = new Bundle();
bundle.putString("inf", info);
//it.putExtra("fahuoren", name);
startActivity(it);
} else{
// failed to create product
//Toast.makeText(getApplicationContext(), " 111",Toast.LENGTH_SHORT).show();
}
} catch(JSONException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String fil_url) {
// TODO Auto-generated method stub
pDialog.dismiss();
}
}
}
public class welcome extends Activity {
TextView tv;
Button btf;
Intent itt = getIntent();
Bundle bun = itt.getExtras();
String information = bun.getString("inf");
String name = bun.getString("fahuoren");
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.welcome);
tv=(TextView)findViewById(R.id.tv);
//tv.setText(information);
btf=(Button)findViewById(R.id.btf);
btf.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent it = new Intent();
it.setClass(getApplicationContext(),fahuo.class);
//it.putExtra("usen", information);
startActivity(it);
}
});
}
}
最后
以上就是还单身盼望为你收集整理的跳转Activity闪退的全部内容,希望文章能够帮你解决跳转Activity闪退所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复