BoundActivity.java


Dosyayı İndir
package com.godoro.androiddevices;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;


public class BoundActivity extends Activity {

    private BoundService service;
    private TextView contentView;

    private ServiceConnection connection=new ServiceConnection(){

        public void onServiceConnected(ComponentName name, IBinder binder) {
            service=((BoundService.BoundBinder)binder).getService();
            String message="Servise bağlanıldı";
            Toast.makeText(BoundActivity.this, message, Toast.LENGTH_SHORT).show();
        }
        public void onServiceDisconnected(ComponentName name) {
            service=null;
            String message="Servis bağlantısı kesildi";
            Toast.makeText(BoundActivity.this, message,Toast.LENGTH_SHORT).show();
        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bound);
        contentView=(TextView) findViewById(R.id.contentView);
    }
    @Override
    protected void onStop() {
        super.onStop();
        if (service!=null) {
            unbindService(connection);
            service = null;
        }
    }
    public void onClickServiceBind(View view) {
        Intent intent=new Intent(this,BoundService.class);
        bindService(intent, connection, Context.BIND_AUTO_CREATE);
    }
    public void onClickServiceConsume(View view) {
        contentView.setText(service.getContent());
    }

}

				
Dosyayı İndir

Bu Sayfayı Paylaş:




Bu Sayfayı Paylaş:

İletişim Bilgileri

Takip Et

Her Hakkı Saklıdır. Bu sitede yayınlanan tüm bilgi ve fikirlerin kullanımından fibiler.com sorumlu değildir. Bu sitede üretilmiş , derlenmiş içerikleri, fibiler.com'u kaynak göstermek koşuluyla kendi sitenizde kullanılabilirsiniz. Ancak telif hakkı olan içeriklerin hakları sahiplerine aittir