bob wrote:

> I don't understand why it lets me do something like this in onCreate: 
>
> Context c = Main_Activity.this; 
>

'Main_Activity' violates the Java naming conventions.
 

>
> That sure looks like a static access.  


No, it doesn't. The 'this' keyword is immediate, conclusive and sufficient 
evidence that this is not a static access. By itself the presence of a dot 
is not /prima facie/ evidence of a static access, except by a very naive 
and uninformed view of the Java language.

The syntax to which you refer is that for an outer instance (NOT a class 
member) when referenced from an inner class. That's just basic Java, which 
you really ought to know in order to program for Android.
 

>
> Justin Anderson wrote: 
> > What does your code look like?  The "this" keyword is not accessed 
> > statically... it is a member of your class instance. 
> > 

 

> bob wrote: 
> > > I tried accessing Main_Activity.this, but Eclipse says: 
> > 
> > > No enclosing instance of the type Main_Activity is accessible in 
> > > scope. 
>

That message is as dead giveaway as to what your mistake was. You didn't 
have an enclosing instance of the type 'Main_Activity' [sic] for that to 
reference.

> > I don't know why it won't let me do it. 

Because you made an outer-instance reference with no outer instance. Thus 
there was no enclosing instance of the type 'Main_Activity', just as the 
error message states. This being illegal, the compiler won't let you do it.
 

> > > Carlos Silva wrote: 
> > > > "this" on a class that extends Activity isn't simple enough? 
>

You can use 'this' in an instance, but not in a static context.

> > > bob wrote: 
> > > > Why is there no static function like Activity.getCurrentActivity()? 
> 
> > > > Right now, I am saving the Activity in a static variable in 
onCreate 
> > > > so I can access it easily later on.  I suspect there must be a 
better 
> > > > way. 

-- 
Lew

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to