我一直想在我的程序使用意向法,code没有显示出错误,当我使用 myactivity.this ...当我用另外两个( myactivity的.class或本),月食显示了一个错误。
意向书I =新意图(myActivity.this,myActivity2.class);startActivity(ⅰ);
当我使用 myactivity.class 或这个中的第一个参数,
Eclipse中显示的没有定义构造意图错误。这是为什么,谁能解释一下吗?
解决方案myActivity.this == Refrence上下文
myActivity2.class ==参考类,这是它的类名
这个 ==这是电流型,说如果你是在线程那么它是螺纹类型;如果你在活动那么它是活动类型;如果你在你的自定义类说CAR则是轿车型
当你做的这个,然后你会得到一个错误,因为你不能在主线程在此你可以使用 getApplicationContext()
当您使用 myActivity.this 它知道它会从这个活动中的的背景下开始了。
I have been trying to use Intent method in my program , the code shows no error when I use myactivity.this ... when I use the other two (myactivity.class or this),eclipse shows an error.
Intent i = new Intent(myActivity.this,myActivity2.class);
startActivity(i);
When I use myactivity.class or this in the first param,
Eclipse shows an error of Constructor Intent not defined. Why is that, can anyone explain?
解决方案myActivity.this == Refrence to context
myActivity2.class == Reference to class, this is its class name
this == It is Current Type, say if you are in Thread then it is Thread Type; if you are in Activity then it is Activity Type; if you are in your custom class say CAR then it is CAR type
When you do the this then you get an error because you must not be in main thread in this you can use getApplicationContext()
When you use myActivity.this It Knows that it will be started from this activitie's context.