> VVMClientApplication is the class where I need to access the VVMService
> class instance.
You don't say why. Are we to assume that VMClientApplication is a
subclass of Application? Apparently not:
> dont I have to extend Application in any class ?
So why did you call it VMClientApplication? Are you trying to confuse
us? :=)
But then you say:
> mService = (VVMService)getApplicationContext();
Which would seem to indicate that you DO extend Application??????
Because to cast something to a VVMService, it actually has to BE a
VVMService. Perhaps you are a C++ programmer, where the casting
operator can be overloaded to become a coercion operator. That doesn't
work in Java.
For that line to make any sense, somewhere you'd have to have
public class VVMService extends Application { .... }
or perhaps
public interface VVMService { ... }
and
public class VMServiceImpl extends Application implements VVMService
{ ... }
And you'd have to declare that as being your application class in the
manifest.
But that doesn't make any sense, either -- you're calling it a
service.
I think your terminology problems suggest that you lack a clear
understanding of the roles of Activity, Application, and Service in
the Android SDK, and also lack a clear understanding of the roles
within your application.
I think spending some more time with the SDK sample applications would
help you with that.
I also suggest including a bit more of your code when you ask further.
Perhaps not everything, but at least the class definition part around
each method definition that you show us. (Ordinarily, I think it's OK
to leave them out, but it seems relevant to the problems you're
having).
On Jul 30, 1:02 pm, Priyank Maiya <[email protected]> wrote:
> Hi,
> I am facing some when running the code. I am using the
> getApplicationContext() to save the instance.
> Kindly have a look at my code and let me know where I am going wrong.
>
> VVMService is the class whose instance is created and got from the
> onServiceConnected() callback
>
> public class VVMServiceBind extends Activity
> {
> public void onCreate(Bundle savedInstanceState)
> {
> super.onCreate(savedInstanceState);
> bindService(new Intent(VVMServiceBind.this, VVMService.class),
> mConnection, Context.BIND_AUTO_CREATE);
> VVMService appState = ((VVMService)getApplicationContext());
> }
>
> public void onServiceConnected(ComponentName className, IBinder
> service)
> {
> Log.i(TAG, "In onServiceConnected");
> mService = ((VVMService.VVMBinder)service).getService();
> appState = mService;
>
> }
>
> }
>
> VVMClientApplication is the class where I need to access the VVMService
> class instance.
>
> public void serviceConnectionSuccess()
> {
> private VVMService mService;
>
> mService = (VVMService)getApplicationContext();
>
> }
>
> dont I have to extend Application in any class ?
>
> Thanks,
> Priyank
>
> On Fri, Jul 30, 2010 at 12:45 PM, Shane Isbell <[email protected]>wrote:
>
>
>
> > Just invoke Activity.getApplication() within your Activity.onCreate method,
> > casting the Application to your specific class type. Then your can set
> > whatever you need on your application instance and it will be accessible
> > within other Activities through the same Activity.getApplication() method.
>
> >http://developer.android.com/reference/android/app/Activity.html#getA...
>
> > On Fri, Jul 30, 2010 at 10:29 AM, Priyank <[email protected]> wrote:
>
> >> Hi,
> >> I had a basic question.
> >> Can my class extend 2 or more classes at a time. What is the syntax.
> >> I want to extend Activity as well as Application. Wont this create
> >> problems in the manifest file?
> >> Activity because, I need to do a couple of things during the
> >> onCreate() [binding a service]and Application, because I am creating
> >> objects of another class [service class]which needs to be accessible
> >> throughout my application.
>
> >> Thanks,
> >> Priyank
>
> >> --
> >> You received this message because you are subscribed to the Google
> >> Groups "Android Developers" group.
> >> To post to this group, send email to [email protected]
> >> To unsubscribe from this group, send email to
> >> [email protected]<android-developers%2Bunsubs
> >> [email protected]>
> >> For more options, visit this group at
> >>http://groups.google.com/group/android-developers?hl=en
>
> > --
> > Shane Isbell (Founder of ZappMarket)
> >http://apps.facebook.com/zappmarket/
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Android Developers" group.
> > To post to this group, send email to [email protected]
> > To unsubscribe from this group, send email to
> > [email protected]<android-developers%2Bunsubs
> > [email protected]>
> > For more options, visit this group at
> >http://groups.google.com/group/android-developers?hl=en
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en