Just a few lines to explain the reason why this
does not work in:
i = new Intent(this, MainActivity.class)
The intent is created inside another class, here an anonymous inner class OnClickListener
. Thus this
does not refer the instance of your Activity (or Context) as intended but the instance of your anonymous inner class OnClickListener
.
So you should provide the correct context of your class.
i = new Intent(YourClassName.this, MainActivity.class)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…