package edu.whs.spin2018.baoapp.views;

import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.Toast;

import edu.whs.spin2018.baoapp.service.BaoService;

/**
 * Legt das Grundverhalten von Aktivitäten, die mit dem Service kommunizieren dar.
 */
public abstract class OnlineActivity extends AppCompatActivity implements ServiceConnection {

    private static final String TAG = "BaseActivity";
    private boolean mBound;

    @Override
    protected void onStart() {
        super.onStart();
        Log.d(TAG, "onStart(): binding Service");
        Intent serviceIntent = new Intent(this, BaoService.class);
        mBound = bindService(serviceIntent, this, Context.BIND_ABOVE_CLIENT);
    }

    @Override
    protected void onStop() {
        super.onStop();
        if(mBound) {
            Log.d(TAG, "onStop(): unbinding Service");
            unbindService(this);
        }
    }
}
