我做了 2 个活动和一个名为 SomeSpecialIntent 的 Intent 扩展类,当您按下第一个活动的 textview 时,您会使用新的 SomeSpecialIntent 类实例转到第二个活动,但在途中会出现一些奇怪的事情,因为短语 getIntent() instnaceof SomeSpecialIntent 返回第二个活动是假的!
那是怎么回事?
我所做的检查代码:
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView textView = (TextView)findViewById(R.id.textView1);
textView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new SomeSpecialIntent(MainActivity.this,SomeActivity.class));
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
public class SomeActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d("Check",""+(getIntent() instanceof SomeSpecialIntent));//returns false!!!!
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
public class SomeSpecialIntent extends Intent {
public SomeSpecialIntent(Context context,
Class<?> class1) {
super(context,class1);
}
}