Friday, July 30, 2010

Re: [android-developers] Extending multiple classes

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 <shane.isbell@gmail.com> 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#getApplication



On Fri, Jul 30, 2010 at 10:29 AM, Priyank <priyankvmaiya@gmail.com> 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 android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
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 android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
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 android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment