0

I am working on adding in-app billing and working from this official documentation

And I am on the section Binding to IInAppBillingService

Here is my code:

public class CommunityActivity extends BaseActivity implements ServiceConnection
{   
    ArrayAdapter<ChatMessage> adapter;
    Dialog dialog;
    ArrayList<ChatMessage> chat = new ArrayList <ChatMessage>( );       

    IInAppBillingService mService;

    ServiceConnection mServiceConn = new ServiceConnection() {
           @Override
           public void onServiceDisconnected(ComponentName name) {
               mService = null;
           }

           @Override
           public void onServiceConnected(ComponentName name, 
              IBinder service) {
               mService = IInAppBillingService.Stub.asInterface(service);
           }
        };

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        FlurryAgent.onStartSession(this, "8CA5LTZ5M73EG8R35SXG");

        setContentView(R.layout.community);

        bindService(new 
                Intent("com.android.vending.billing.InAppBillingService.BIND"),
                        mServiceConn, Context.BIND_AUTO_CREATE);

But I get compile errors saying I have to implement the onServiceConnected and onServiceDisconnected methods. But I thought I already added them in a way that the example suggested.

Where did I go wrong here? Thanks!

Genadinik
  • 18,153
  • 63
  • 185
  • 284

1 Answers1

1

The error is because you have declared your class as follows

public class CommunityActivity extends BaseActivity implements ServiceConnection

now compiler expects that u have these two functions onServiceConnected and on ServiceDisconnected implemented in CommunityActivity. but it cannot find them in this class.

remove this implements ServiceConnection and code should compile successfully.

Kinaan Khan Sherwani
  • 1,504
  • 16
  • 28
  • thanks, but it says in that section that I should implement that ServiceConnection interface. Or did I misunderstand it? – Genadinik Aug 10 '13 at 12:21
  • you are already implementing the interface here `ServiceConnection mServiceConn = new ServiceConnection(){ .... }` and `mServiceConn` is basically that you are already using in `bindService()` . you don't need `implements ServiceConnection` in the class definition anymore . – Kinaan Khan Sherwani Aug 10 '13 at 12:24