Bellekten Tamamen Kaldırılan Uygulama Çalışmaya Devam Ediyor.
24.12.2013 - 04:55
Merhaba,
Service ile çalışan bir radyo uygulaması geliştiriyorum. Uygulama çalışırken home tuşuna basıp ardından da uygulamayı stoplamadan telefonun belleğinden kaldırdıgımda bir kac saniye kapalı kalıyor sonra calısmayı sürdürüyor. Bu sıkıntıyı nasıl aşabilirim?
Service im;
[code] package com.denemeservis; import java.io.IOException; import android.app.Service; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.media.MediaPlayer; import android.media.MediaPlayer.OnBufferingUpdateListener; import android.media.MediaPlayer.OnPreparedListener; import android.os.IBinder; import android.telephony.PhoneStateListener; import android.telephony.TelephonyManager; import android.util.Log; import android.widget.Toast; public class DinlemeServisi extends Service { private final String url[] = { "http://85.95.248.115:8014/"}; public static Boolean phoneRinging = false; private MediaPlayer player; @Override public int onStartCommand(Intent intent, int flags, int startId) { Log.d("onStart", "onStart"); dinlemeBaslasin(); startPlaying(); /*if(url[0] != null){ intent.putExtra("http://85.95.248.115:8014/", 0); }if(url[1] != null){ intent.putExtra("http://yayin2.yayindakiler.com:4056/", 1); }if(url[2] !=null){ intent.putExtra("http://85.95.248.115:8008/", 2); }if(url[3] !=null){ intent.putExtra("http://85.95.248.115:8006/", 3); }if(url[4] !=null){ intent.putExtra("http://85.95.248.115:8018/", 4); }if(url[5] !=null){ intent.putExtra("http://85.95.248.115:8002/", 5); }*/ return Service.START_STICKY; } @Override public IBinder onBind(Intent intent) { return null; } @Override public void onDestroy() { super.onDestroy(); Log.d("onDestroy", "onDestroy"); stopPlaying(); if (player != null) { if (player.isPlaying()) { player.stop(); } player.release(); } } private void dinlemeBaslasin() { Log.d("dinlemeBaslasin", "dinlemeBaslasin"); player = new MediaPlayer(); try { player.setDataSource(url[0]); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalStateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } player.setOnBufferingUpdateListener(new OnBufferingUpdateListener() { @Override public void onBufferingUpdate(MediaPlayer mp, int percent) { Log.d("Buffering", "" + percent); } }); } private void startPlaying() { Log.d("startPlaying", "startPlaying"); player.prepareAsync(); player.setOnPreparedListener(new OnPreparedListener() { @Override public void onPrepared(MediaPlayer mp) { Toast.makeText(getApplicationContext(), "Yayın Başladı", Toast.LENGTH_SHORT).show(); player.start(); player.isLooping(); } }); } private void stopPlaying() { Toast.makeText(getApplicationContext(), "Yayın Durdu", Toast.LENGTH_SHORT) .show(); Log.d("stopPlaying", "stopPlaying"); player.stop(); player.release(); dinlemeBaslasin(); } } [/code]
24
Görüntülenme
0 Beğeni