> are you calling it after you have binded ?
YES, i have binded

> You are mentioning onCreate(), I just hope the code-sequence is the
Please find my code a below..
---------------------------------------------------------------
Activity Code
public class Launcher extends Activity {
      private IMainService mService = null;
      TextView tView1 = null;
      String testvar1 = "";
      /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.status_display);
        tView1 = (TextView)findViewById(R.id.feed_service_status);

        bindService(new Intent(IMainService.class.getName()), serCon,
Context.BIND_AUTO_CREATE);
            Button refresh_button =
(Button)findViewById(R.id.refresh_button);
            refresh_button.setOnClickListener(new
View.OnClickListener() {

                  @Override
                  public void onClick(View v) {
                        // TODO Auto-generated method stub
                        fill_vals();  ////--->Can access from here
                  }
            });
             fill_vals();  ////---- Cannot Access from here...
mService goes null and throw nullpointerexception.
    }

    private void fill_vals() {
      String tets = "";
      try {
                  tets = mService.ServiceStatus();
            } catch (RemoteException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
                  tets = e.getMessage();
            }
    }

    public ServiceConnection serCon = new ServiceConnection() {

            @Override
            public void onServiceDisconnected(ComponentName name) {
                  // TODO Auto-generated method stub
            }

            @Override
            public void onServiceConnected(ComponentName name, IBinder
service) {
                  // TODO Auto-generated method stub
                  mService = MainServiceImpl.asInterface(service);

            }
      };

}
----------------------------------------------------------

> myServiceIntent = new Intent(this,service.class);
> this.bindService(myServiceIntent, mConnection,
> Context.BIND_AUTO_CREATE);
I have tried setting intents all the ways, by this method, by method
as i mentioned in code, tried by calling setClassName. but i dont
think that does make difference.




On Jun 25, 4:57 pm, MobDev <[email protected]> wrote:
> Well,
> are you calling it after you have binded ?
> You are mentioning onCreate(), I just hope the code-sequence is the
> right one, thus something like :
>
> myServiceIntent = new Intent(this,service.class);
> this.bindService(myServiceIntent, mConnection,
> Context.BIND_AUTO_CREATE);
>
> On 25 jun, 11:40, vineet <[email protected]> wrote:
>
> > i am usign a very simple scenario.
> > i have a remote service created and binded properly.
> > I can access service methods as described in the aidl interface but
> > only from the click listener, and can never access using it using
> > onCreate or other functions.
>
> > i have tried 3 different approaches as available on books or net to
> > consume service. however result is same.
>
> > for instance if i create mSercvice as my Service class variable and in
> > the interface i have method getStatus() which returns boolean.
>
> > now after binding service if i call mService.getStatus() from
> > onClickListener or ServiceConnection Stub, ican access very easily
> > without a error.
> > but if i try to get from onCreate (my app fetches parameter status
> > from service), the value of mService gets null and system exits with
> > Force Close (due to nullpointexception as from log).
>
> > Now can somone please help, as i dont think the value should be null
> > since the variable is declared globally. so how does the stuff goes..
>
> > One of my friend on this group told, if you dont get output all times,
> > its a bug.
>
> > sorry for bad english...
>
>

-- 
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

Reply via email to