Question

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!

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top