java - What is the difference between `this` and `ActivityClass.this` in android intent constructor? -
this question has answer here:
what difference between this
, activityclass.this
when pass in intent constructor
for example given 2 activities: activityone , activitytwo
the following doesn't work (compile error)
@override public void onclick(view v) { intent intent = null; log.i(tag, this.tostring()); log.i(tag, activityone.this.tostring()); intent = new intent(this, activitytwo.class); startactivity(intent); }
while works
@override public void onclick(view v) { intent intent = null; log.i(tag, this.tostring()); log.i(tag, activityone.this.tostring()); intent = new intent(activityonethis, activitytwo.class); startactivity(intent); }
the logging info log
activitylab.activityone$1@41fc5818 activitylab.activityone@41fa2948
although different, common answer passing activity using this
, not why running problem
i'm assuming onclick
method inside anonymous class instance (though didn't include full code, activityone$1
output see when printing this
how anonymous inner classes displayed), refers anonymous inner class instance, , not activityone
instance containing instance.
activityone.this
returns reference containing activityone
instance, supposed pass intent
constructor.
Comments
Post a Comment