Hi, here is my activity class. package com.musix.main; import java.io.BufferedReader;
import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.HttpURLConnection; import java.net.Socket; import java.net.URL; import java.util.ArrayList; import java.util.List; import org.apache.http.NameValuePair; import org.apache.http.message.BasicNameValuePair; import org.json.JSONObject; import com.musix.http.HttpRetriever; import com.musix.model.Parser; import com.musix.utils.UrlConstants; import android.app.Activity; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.Bundle; import android.os.Handler; import android.os.IBinder; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.view.Window; import android.widget.ImageButton; import android.widget.ImageView; import android.widget.TextView; public class StreamingPlayerView extends Activity implements OnClickListener,Parser { private ImageButton btnplay; private TextView txtsongname,txtalbumartistname; public boolean isRadioOn=false; Handler handler=new Handler(); private static String title,albumTitle,artistName; private ImageView imageView; public NotificationService notificationService=null; PrintWriter out=null; BufferedReader in=null; public static boolean isSocketOpen=false; Socket socket=null; public void onCreate(Bundle instance) { super.onCreate(instance); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.streamingplayerview); txtsongname = (TextView) findViewById(R.id.txtsongname); txtalbumartistname = (TextView) findViewById(R.id.txtalbumartistname); imageView=(ImageView)findViewById(R.id.imgalbumart); btnplay = (ImageButton) findViewById(R.id.play); btnplay.setOnClickListener(this); listenForTrackChange(); Intent serviceIntent=new Intent(); serviceIntent.setClass(getApplicationContext(),NotificationService.class); bindService(serviceIntent,serviceConnection,Context.BIND_AUTO_CREATE); startService(serviceIntent); } private void setTrackdetails() { try { txtsongname.setText(title); txtalbumartistname.setText(albumTitle+"-"+artistName); } catch (Exception e) { e.printStackTrace(); } } @Override public void onClick(View v) { switch (v.getId()) { case R.id.play: if (StremingPlayer.streamingPlayer.isPlaying()) { StremingPlayer.streamingPlayer.pause(); btnplay.setBackgroundResource(R.drawable.play_button); LocalMediaPlayer.isPaused = true; } else { btnplay.setBackgroundResource(R.drawable.pause_button); StremingPlayer.streamingPlayer.start(); } break; default: break; } } private void listenForTrackChange() { new Thread() { public void run() { if(!isSocketOpen) { try { try { String line; socket=new Socket("host",1934); out = new PrintWriter(socket.getOutputStream(), true); in = new BufferedReader(new InputStreamReader(socket.getInputStream())); out.println("OPEN CHANNEL ARTIST "+StremingPlayer.CURRENTARTISTID); while ((line=in.readLine())!=null) { String delimeter1="="; String delimeter2="&"; String trackid=line.substring(line.indexOf(delimeter1),line.indexOf(delimeter2)); List<NameValuePair> nameValues = new ArrayList<NameValuePair>(); nameValues.add(new BasicNameValuePair("sid", SplashScreen.sidvalue)); HttpRetriever httpThread = new HttpRetriever( UrlConstants.BASEURL + UrlConstants.TRACK+"&id"+trackid, nameValues, StreamingPlayerView.this, UrlConstants.NEWSLISTINDEX); httpThread.start(); isSocketOpen=true; } } catch (IOException e) { e.printStackTrace(); } finally { try { if (in!=null) in.close(); } catch (IOException e) {e.printStackTrace();}; if (out!=null) out.close(); try { if (socket!=null) socket.close(); isSocketOpen=false; } catch (IOException e) { e.printStackTrace(); }; } } catch (Exception e) { e.printStackTrace(); } } } }.start(); } private void downloadImage(String url) { URL imageurl; final Bitmap bitmapImage; try { imageurl=new URL(url); HttpURLConnection httpConn=(HttpURLConnection)imageurl.openConnection(); httpConn.setDoOutput(true); httpConn.connect(); InputStream is=httpConn.getInputStream(); bitmapImage=BitmapFactory.decodeStream(is); handler.postDelayed(new Runnable() { @Override public void run() { imageView.setImageBitmap(bitmapImage); } },100); } catch (Exception e) { e.printStackTrace(); } } @Override public void parseData(String data, int index) { try { JSONObject object=new JSONObject(data); title=object.optString("title"); albumTitle=object.optString("albumTitle"); artistName=object.optString("artistName"); handler.postDelayed(new Runnable() { @Override public void run() { setTrackdetails(); notificationService.ShowNotification1(title, artistName); } },100); downloadImage(object.optString("imageUrl")); } catch (Exception e) { e.printStackTrace(); } } public void onDestroy() { super.onDestroy(); try { if(in!=null) in.close(); if(out!=null) out.close(); if(socket!=null) socket.close(); isSocketOpen=false; } catch (Exception e) { e.printStackTrace(); } } public ServiceConnection serviceConnection=new ServiceConnection() { @Override public void onServiceDisconnected(ComponentName name) { notificationService=null; } @Override public void onServiceConnected(ComponentName name, IBinder service) { notificationService=((NotificationService.LocalBinder)service).getservice(); } }; } On Tue, Jun 21, 2011 at 2:19 AM, Zsolt Vasvari <zvasv...@gmail.com> wrote: > You just showed us about 30 lines of code. Do we look like mind > readers who can figure out your problem without showing any kind of > error log or stack trace? > > On Jun 21, 4:50 pm, Hitendrasinh Gohil <hitendra.virtuei...@gmail.com> > wrote: > > Hi, > > .when the activity is visible > > there isnt any problem.but when i navigate to previous screen and > > again going to this activity it causes forced close to my app. > > how to resolve this? > > > > > > > > > > > > On Tue, Jun 21, 2011 at 12:41 AM, Zsolt Vasvari <zvasv...@gmail.com> > wrote: > > > Ok, cool. Do you have a question? > > > > > On Jun 21, 3:35 pm, Hitendrasinh Gohil <hitendra.virtuei...@gmail.com> > > > wrote: > > > > Hi, > > > > > > I am using thread in my activity class.when the activity is visible > > > > there isnt any problem.but when i navigate to previous screen and > > > > again going to this activity it causes forced close to my app.I have > > > > tried it by removing the thread then it works fine. > > > > > > Here is the code that i m calling from onCreate method. > > > > > > private void listenForTrackChange() > > > > { > > > > new Thread() > > > > { > > > > public void run() > > > > { > > > > if(!isSocketOpen) > > > > { > > > > try > > > > { > > > > try > > > > { > > > > String line; > > > > socket=new > > > Socket("host",1934); > > > > out = new > > > PrintWriter(socket.getOutputStream(), true); > > > > in = new > BufferedReader(new > > > > InputStreamReader(socket.getInputStream())); > > > > out.println("OPEN CHANNEL > > > ARTIST > > > > "+StremingPlayer.CURRENTARTISTID); > > > > while > > > ((line=in.readLine())!=null) > > > > { > > > > String > delimeter1="="; > > > > String > delimeter2="&"; > > > > String > > > > > > trackid=line.substring(line.indexOf(delimeter1),line.indexOf(delimeter2)); > > > > List<NameValuePair> > > > nameValues = new > > > > ArrayList<NameValuePair>(); > > > > > nameValues.add(new BasicNameValuePair("sid", > > > > > SplashScreen.sidvalue)); > > > > > HttpRetriever httpThread = new HttpRetriever( > > > > > UrlConstants.BASEURL + UrlConstants.TRACK+"&id"+trackid, > > > > nameValues, > > > > > StreamingPlayerView.this, UrlConstants.NEWSLISTINDEX); > > > > > httpThread.start(); > > > > > isSocketOpen=true; > > > > } > > > > > > } > > > > catch (IOException e) > > > > { > > > > e.printStackTrace(); > > > > } > > > > finally > > > > { > > > > try > > > > { > > > > if (in!=null) > > > > in.close(); > > > > } > > > > catch (IOException e) > > > {e.printStackTrace();}; > > > > if (out!=null) > out.close(); > > > > try > > > > { > > > > if (socket!=null) > > > > > socket.close(); > > > > isSocketOpen=false; > > > > } > > > > catch (IOException e) > > > > { > > > > e.printStackTrace(); > > > > }; > > > > } > > > > } > > > > catch (Exception e) > > > > { > > > > e.printStackTrace(); > > > > } > > > > } > > > > } > > > > }.start(); > > > > } > > > > > -- > > > You received this message because you are subscribed to the Google > > > Groups "Android Developers" group. > > > To post to this group, send email to > android-developers@googlegroups.com > > > To unsubscribe from this group, send email to > > > android-developers+unsubscr...@googlegroups.com > > > For more options, visit this group at > > >http://groups.google.com/group/android-developers?hl=en > > > > -- > > Regards, > > Hitendrasinh Gohil- Hide quoted text - > > > > - Show quoted text - > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to android-developers@googlegroups.com > To unsubscribe from this group, send email to > android-developers+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en > -- Regards, Hitendrasinh Gohil -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en