我有一个奇怪的问题
我在MainActivity上创建了一个Bundle
并且条件if(bundle!= Null)
但是在第一次运行中,程序为n null并且程序关闭。我的代码:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_class);
Bundle bundle = getIntent().getExtras();
if (bundle != null) {
Log.d("tag", "onCreate0: ");
Width = Double.parseDouble(bundle.getString("Width"));
height = Double.parseDouble(bundle.getString("height"));
}
}
答案 0 :(得分:0)
我自己解决了
Intent intent11 = new Intent(context, MainClass.class);
int strName = -1;
intent11.putExtra("STRING_I_NEED", strName);
intent11.putExtra("Width", Width);
intent11.putExtra("height", height);
intent11.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent11);
Bundle bundle = getIntent().getExtras();
if (bundle != null) {
if (bundle.getInt("STRING_I_NEED") == -1) {
Width = Double.parseDouble(bundle.getString("Width"));
height = Double.parseDouble(bundle.getString("height"));
}
}