我创建了2个活动和一个名为SomeSpecialIntent的Intent扩展类,当你按下第一个活动的textview时,你会使用新的SomeSpecialIntent类instnace转到第二个,但是路上有一些奇怪的东西,因为短语getIntent() instnaceof SomeSpecialIntent在第二个活动上返回false!
是什么意思?
我所做的支票代码:
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);
}
}