ServieConnection 根本不工作 Android

ServieConnection Not Working At All Android

很好 Day.I 有最简单的场景!我有简单的服务连接,取自 google 在应用程序购买示例中,这是我自己的代码

public class MainActivity extends Activity {
IInAppBillingService mService;
ServiceConnection mServiceConn;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
     mServiceConn = new ServiceConnection() {
        @Override
        public void onServiceDisconnected(ComponentName name) {
            mService = null;
            Toast.makeText(MainActivity.this,"disconnected",Toast.LENGTH_LONG).show();
        }

        @Override
        public void onServiceConnected(ComponentName name,
                                       IBinder service) {
            mService = IInAppBillingService.Stub.asInterface(service);
            Toast.makeText(MainActivity.this,"connected",Toast.LENGTH_LONG).show();
        }
    };
}
@Override
public void onDestroy() {
    super.onDestroy();
    if (mService != null) {
        unbindService(mServiceConn);
    }
}

} 对于第一个 运行 它有效并且它 toasted.But 之后它永远不会连接永远不会触发 onserviceconnected 并且 onservicedisconnected.Doing 在 google 中进行研究我没有找到任何解决方案但只有熟悉的问题没有任何负责任的 answers.Thank 你事先请告诉我到底要做什么?

您没有调用绑定服务:

创建意图并调用 bindService

    @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
             mServiceConn = new ServiceConnection() {
                @Override
                public void onServiceDisconnected(ComponentName name) {
                    mService = null;
                    Toast.makeText(MainActivity.this,"disconnected",Toast.LENGTH_LONG).show();
                }

                @Override
                public void onServiceConnected(ComponentName name,
                                               IBinder service) {
                    mService =   IInAppBillingService.Stub.asInterface(service);
                    Toast.makeText(MainActivity.this,"connected",Toast.LENGTH_LONG).show();
                }
            };

    IntentFilter filter1 = new IntentFilter("IntentFilterName");
    bindService(filter1, mConnection, Context.BIND_AUTO_CREATE);
}