Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7458043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T13:23:55+00:00 2026-05-29T13:23:55+00:00

I have 2 activities lets say A and B. In the first one(A) I

  • 0

I have 2 activities lets say A and B. In the first one(A) I am choosing my listview and in the second one I am listing this listview (radio stations) and using a media player I am playing from this listview.
What I am trying to do is, while listening the radio station in the second activity(B), I want to go back to the previous activity and choose the other listview and update the listview of Activity B.
Simply I am trying to go back from activity B to A. But I cannot. When I press the back button of the emulator it gave me errors. I am also trying to make a back button my self. Same purpose but just one in the app.

Could you please help me, what was I doing wrong? Because in my previous apps back button and home button was functioning properly without doing anything. In this one neither of them functioning. I am using 2.2 SDK

LogCat:

02-13 02:42:52.106: E/AndroidRuntime(874): FATAL EXCEPTION: main
02-13 02:42:52.106: E/AndroidRuntime(874): java.lang.RuntimeException: Unable to pause activity {com.beanie.samples.streaming/com.beanie.samples.streaming.HomeActivity}: java.lang.NullPointerException
02-13 02:42:52.106: E/AndroidRuntime(874):  at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3348)
02-13 02:42:52.106: E/AndroidRuntime(874):  at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3305)
02-13 02:42:52.106: E/AndroidRuntime(874):  at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:3288)
02-13 02:42:52.106: E/AndroidRuntime(874):  at android.app.ActivityThread.access$2500(ActivityThread.java:125)
02-13 02:42:52.106: E/AndroidRuntime(874):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2044)
02-13 02:42:52.106: E/AndroidRuntime(874):  at android.os.Handler.dispatchMessage(Handler.java:99)
02-13 02:42:52.106: E/AndroidRuntime(874):  at android.os.Looper.loop(Looper.java:123)
02-13 02:42:52.106: E/AndroidRuntime(874):  at android.app.ActivityThread.main(ActivityThread.java:4627)
02-13 02:42:52.106: E/AndroidRuntime(874):  at java.lang.reflect.Method.invokeNative(Native Method)
02-13 02:42:52.106: E/AndroidRuntime(874):  at java.lang.reflect.Method.invoke(Method.java:521)
02-13 02:42:52.106: E/AndroidRuntime(874):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
02-13 02:42:52.106: E/AndroidRuntime(874):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
02-13 02:42:52.106: E/AndroidRuntime(874):  at dalvik.system.NativeStart.main(Native Method)
02-13 02:42:52.106: E/AndroidRuntime(874): Caused by: java.lang.NullPointerException
02-13 02:42:52.106: E/AndroidRuntime(874):  at com.beanie.samples.streaming.HomeActivity.onPause(HomeActivity.java:439)
02-13 02:42:52.106: E/AndroidRuntime(874):  at android.app.Activity.performPause(Activity.java:3842)
02-13 02:42:52.106: E/AndroidRuntime(874):  at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1190)
02-13 02:42:52.106: E/AndroidRuntime(874):  at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3335)

I also tried to implement onBackPressed, but it did not work.

@Override
    public void onBackPressed() {
        // TODO Auto-generated method stub
        super.onBackPressed();
        Intent info = new Intent(B_Activity.this,A_Activity.class);
            moveTaskToBack(true);
        info.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
        startActivity(info);
    }

Here is my Activity A

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class index extends Activity implements OnClickListener{
Button btnYerli,btnYabanci,btnFvrKanal,btnFvrSarki,btnRecs;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);

        setContentView(R.layout.index);

        initializeUI();

        if (AppStatus.getInstance(this).isOnline(this)) {

            Toast t = Toast.makeText(this,"You are online!!!!",8000);
            t.show();       
            } else{  
                  Toast t = Toast.makeText(this,"You are not online!!!!",8000);
                  t.show();
                  Log.v("Home", "You are not online!!!!");    
             }      
    }
    public void initializeUI(){
        btnYerli = (Button) findViewById(R.id.btnYerli);
        btnYerli.setOnClickListener(this);

        btnYabanci = (Button) findViewById(R.id.btnYabanci);
        btnYabanci.setOnClickListener(this);

        btnFvrKanal = (Button) findViewById(R.id.btnKanalFvr);
        btnFvrKanal.setOnClickListener(this);

        btnFvrSarki = (Button) findViewById(R.id.btnSarkiFvr);
        btnFvrSarki.setOnClickListener(this);

        btnRecs = (Button) findViewById(R.id.btnRecs);
        btnRecs.setOnClickListener(this);

    }

    public void onClick(View arg0) {
        // TODO Auto-generated method stub
        //String kanalList="yerli";
        switch(arg0.getId()){
        case R.id.btnYerli:
            Intent openHomeActivityYerli = new Intent("com.beanie.samples.streaming.HOMEACTIVITY");     
            openHomeActivityYerli.putExtra("kanalList","yerli");
            startActivity(openHomeActivityYerli);
        break;
        case R.id.btnYabanci:
            Intent openHomeActivityYabanci = new Intent(index.this,HomeActivity.class);
            openHomeActivityYabanci.putExtra("kanalList","yabanci");
            startActivityForResult(openHomeActivityYabanci,0);
        break;
        case R.id.btnKanalFvr:
            Intent openHomeActivityFavoriKanal = new Intent("com.beanie.samples.streaming.HOMEACTIVITY");
            openHomeActivityFavoriKanal.putExtra("kanalList","favori");
            startActivity(openHomeActivityFavoriKanal);
        break;
        }
    }
}

And here is my Activiy B

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.spoledge.aacdecoder.AACPlayer;

import android.app.ListActivity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.gesture.Gesture;
import android.gesture.GestureLibraries;
import android.gesture.GestureLibrary;
import android.gesture.GestureOverlayView;
import android.gesture.Prediction;
import android.gesture.GestureOverlayView.OnGesturePerformedListener;
import android.graphics.Color;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnBufferingUpdateListener;
import android.media.MediaPlayer.OnPreparedListener;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

public class HomeActivity extends ListActivity implements OnClickListener, OnGesturePerformedListener{

    private String[] radioNames;
    private String[] radioUrls; 
    private String[] favoriteRadioNames;
    private String[] favoriteRadioUrls;
    private String selectedRadioUrl="http://46.20.4.58:8040/";
    private String selectedRadioName="Select a radio station";
    private String artist;
    private String song;
    private String stopMsg;
    private String welcomeMsg;
    private String noServerConnectionMsg;
    private boolean favoriteButton=true;
    private boolean metaDataThreadStop=false;
    private int mediaType=1;
    private int channelList=1;

    private String JSONUrl; 
    private JSONObject JSONStations;

    private ProgressBar playSeekBar;
    private Button buttonChannelList;
    private Button buttonStopPlay; 
    private Button buttonBack; 
    private TextView stationView,artistView,songView;

    //private Button buttonRecord;
    //private Button buttonStopRecord;

    private MediaPlayer player;
    private AACPlayer aacPlayer;

    private Map<String, ?> favoriteChannelsMap;
    private GestureLibrary mLibrary;

    private Thread getMetaData;

    //private InputStream recordingStream;
    //private RecorderThread recorderThread;
    //private boolean isRecording = false;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {

        SharedPreferences favoriteChannels = getSharedPreferences("favorite_channels_list", 0);

        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);  

        initializeUIElements();
        setChannelChoice();

        JSONStations = getJSONfromURL(JSONUrl);
        if(JSONStations == null){
            Toast t = Toast.makeText(this,noServerConnectionMsg,8000);
            t.show();
            radioNames = getResources().getStringArray(R.array.radioName);    
            radioUrls = getResources().getStringArray(R.array.radioURL);  
        }else{
            parseJSONtoArray(JSONStations);
        }

        mLibrary = GestureLibraries.fromRawResource(this, R.raw.radiogestures);
        if (!mLibrary.load()) {
            finish();
        }

        GestureOverlayView gestures = (GestureOverlayView) findViewById(R.id.gestures);
        gestures.addOnGesturePerformedListener(this);
        gestures.setGestureColor(Color.TRANSPARENT);

        initializeMediaPlayer();        
        stationView.setText(welcomeMsg);

        chooseChannelList();     
    }

    private void initializeUIElements() {

        stopMsg = getResources().getString(R.string.stopMsg);
        welcomeMsg=getResources().getString(R.string.welcomeMsg);
        noServerConnectionMsg=getResources().getString(R.string.noServerConnection);

        stationView = (TextView) findViewById(R.id.stationView);
        artistView = (TextView) findViewById(R.id.artistView);
        songView = (TextView) findViewById(R.id.songView);

        //channelList = (TextView) findViewById(R.id.channelList);
        //channelList.setOnClickListener(this);

        //likeCheckBox =(CheckBox) findViewById(R.id.likeCheckBox);
        //likeCheckBox.setOnClickListener(this);

        playSeekBar = (ProgressBar) findViewById(R.id.progressBar1);
        playSeekBar.setMax(100);
        playSeekBar.setVisibility(View.INVISIBLE);

        buttonChannelList = (Button) findViewById(R.id.buttonChannelList);
        buttonChannelList.setOnClickListener(this);

        buttonBack =(Button) findViewById(R.id.buttonBack); 
        buttonBack.setOnClickListener(this);

        getFavoritChannels();
        if (favoriteChannelsMap.isEmpty()){
            buttonChannelList.setEnabled(false);
        }else{
            buttonChannelList.setEnabled(true);
        }

        buttonStopPlay = (Button) findViewById(R.id.buttonStopPlay);
        buttonStopPlay.setEnabled(false);
        buttonStopPlay.setOnClickListener(this);

        /*buttonRecord = (Button) findViewById(R.id.buttonRecord);
        buttonRecord.setOnClickListener(this);

        buttonStopRecord = (Button) findViewById(R.id.buttonStopRecord);
        buttonStopRecord.setOnClickListener(this);*/
    }

    @Override
    public void onBackPressed() {
        // TODO Auto-generated method stub
        super.onBackPressed();
        Toast t = Toast.makeText(this,"Back Button",8000);
        t.show();
    }

    private void setChannelChoice(){
        Bundle extras = getIntent().getExtras();
        if(extras !=null) {
            String channels = extras.getString("kanalList");  
            if(channels.compareTo("yerli")==0){
                JSONUrl = getResources().getString(R.string.JSONUrlYerli);
                channelList = 1;
            }
            else if (channels.compareTo("yabanci")==0){
                JSONUrl = getResources().getString(R.string.JSONUrlYabanci);
                channelList = 1;
            }
            else if(channels.compareTo("favori")==0){
                channelList = 2;    
            }

        }else{

        }
    }

    private void chooseChannelList(){
        switch(channelList){
        case 1:
            showChannelsList();
        break;
        case 2:
            showFavoriteChannelList();      
        break;
        }   
    }

    private void parseJSONtoArray(JSONObject JSONText){
        List<String> radioNamesArrayList = new ArrayList<String>();
        List<String> radioURLsArrayList = new ArrayList<String>();      
        try {
            JSONObject KanallarObject = JSONText.getJSONObject("Kanallar");
            //String versionString = KanallarObject.getString("Version");
            JSONArray kanalArray = KanallarObject.getJSONArray("Kanal");
            for(int i=0;i < kanalArray.length();i++){  
                radioNamesArrayList.add(kanalArray.getJSONObject(i).getString("Isim").toString());
                radioURLsArrayList.add(kanalArray.getJSONObject(i).getString("Adres").toString());
            }

        } catch (JSONException e) {
            // TODO Auto-generated catch block
            Log.e("log_tag", "Error parsing data "+e.toString());       
        }
        radioNames = radioNamesArrayList.toArray(new String[radioNamesArrayList.size()]);
        radioUrls = radioURLsArrayList.toArray(new String[radioURLsArrayList.size()]);
    }

    public void onClick(View v) {
        switch (v.getId()){
        case R.id.buttonBack:    
            Intent info = new Intent(HomeActivity.this,index.class);
            Log.d("1","1");
            moveTaskToBack(true);
            Log.d("2","2");
            info.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
            Log.d("3","3");

            startActivityForResult(info,0);
        break;
        case R.id.buttonChannelList:
            if (favoriteButton){
                showFavoriteChannelList();
            }else{
                showChannelsList();
            }
        break;
        case R.id.buttonStopPlay:
            stopPlaying();
        break; 
        }
        /*else if (v == buttonRecord) {
            recorderThread = new RecorderThread();
            recorderThread.start();

            buttonRecord.setEnabled(false);
            buttonStopRecord.setEnabled(true);
        } else if (v == buttonStopRecord) {
            stopRecording();
        }*/
    }

    @Override
    protected void onRestart() {
        // TODO Auto-generated method stub
        super.onRestart();
        Log.d("onReStart","^^^^^^^^^RESTART^^^^^^");

    }

    @Override
    protected void onResume() {
        // TODO Auto-generated method stub
        super.onResume();
        Log.d("onResume","^^^^^^^^^RESUME^^^^^^");

    }

    @Override
    protected void onStart() {
        // TODO Auto-generated method stub
        super.onStart();
        Log.d("onStart","^^^^^^^^^START^^^^^^");
    }

    @Override
    protected void onStop() {
        // TODO Auto-generated method stub
        super.onStop();
        Log.d("onStop","^^^^^^^^^STOP^^^^^^");
    }


    private void startPlaying() {

        stationView.setText(selectedRadioName);
        buttonStopPlay.setEnabled(true);
        playSeekBar.setVisibility(View.VISIBLE);
        initializeMediaPlayer();

        switch(mediaType){
        case 1:
            aacPlayer.playAsync(selectedRadioUrl);
            metaDataThreadStop=false;
            getMetaData = new Thread(){
                    public void run(){                  
                        getMeta();                                  
                    }   
            };
            getMetaData.start();
            break;
        case 2:
            player.setAudioStreamType(AudioManager.STREAM_RING);     
            player.prepareAsync();                
            player.setOnPreparedListener(new OnPreparedListener() {
                public void onPrepared(MediaPlayer mp) {  
                    player.start();     
                    //buttonRecord.setEnabled(true);
                }
            });
            break;
        }

    }

    private void stopPlaying() {
        int i=0;
        stationView.setText(stopMsg);
        switch(mediaType){
        case 1:
            aacPlayer.stop();
            //aacPlayer.
            metaDataThreadStop=true;
            /*if (getMetaData!=null){
                Log.d("Stop","threadNULL");
                getMetaData.interrupt();
                Log.d("threadInterrupted",String.valueOf(getMetaData.isInterrupted()));             
                try{
                    Log.d("Stop","threadJoin");
                    getMetaData.join();
                }catch(InterruptedException e){
                    Thread.currentThread().interrupt();
                }
            }*/
            break;
        case 2:
            if (player.isPlaying()){
            player.stop();
             //aacPlayer.stop();
             player.release();
            }
            break;
        }
        buttonChannelList.setEnabled(true);
        buttonStopPlay.setEnabled(false);
        playSeekBar.setVisibility(View.INVISIBLE);
        //buttonRecord.setEnabled(false);
        //buttonStopRecord.setEnabled(false);
        /*stopRecording();*/
    }

    private void initializeMediaPlayer() {
        switch(mediaType){
        case 1:
            aacPlayer = new AACPlayer();
            break;
        case 2:
            player = new MediaPlayer();       
            try {
                player.setDataSource(selectedRadioUrl);      
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            } catch (IllegalStateException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            player.setOnBufferingUpdateListener(new OnBufferingUpdateListener() {
                public void onBufferingUpdate(MediaPlayer mp, int percent) {
                    playSeekBar.setSecondaryProgress(percent);
                    Log.i("Buffering", "" + percent);
                }
            });
            break;
        }
    }

    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
        // TODO Auto-generated method stub
        //super.onListItemClick(l, v, position, id);
        String selection = l.getItemAtPosition(position).toString();
        Toast.makeText(this, selection, Toast.LENGTH_LONG).show();
        artistView.setText("looking for artist info");
        songView.setText("looking for song info");
        if (favoriteButton){
            selectedRadioUrl = radioUrls[position];
            selectedRadioName = radioNames[position];
        }else{
            selectedRadioUrl = favoriteRadioUrls[position];
            selectedRadioName = favoriteRadioNames[position];
        }
        switch(mediaType){
        case 1:
            stopPlaying();
            startPlaying();
            break;
        case 2:
            if (player.isPlaying()) {
            stopPlaying();
            startPlaying();
            }
            else{      
                startPlaying();    
                }
            break;
        }
    }

    @Override
    protected void onPause() {
        super.onPause();
        if (player.isPlaying()) {
            player.stop();
        }
    }

    public static JSONObject getJSONfromURL(String url){

        //initialize
        InputStream is = null;
        String result = "";
        JSONObject jArray = null;

        //http post
        try{
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost(url);
            HttpResponse response = httpclient.execute(httppost);
            HttpEntity entity = response.getEntity();
            is = entity.getContent();

        }catch(Exception e){
            Log.e("log_tag", "Error in http connection "+e.toString());
        }

        //convert response to string
        try{
            BufferedReader reader = new BufferedReader(new InputStreamReader(is,"UTF-8"),8000);
            StringBuilder sb = new StringBuilder();
            String line = null;
            while ((line = reader.readLine()) != null) {
                sb.append(line + "\n");
            }
            is.close();
            result=sb.toString();
        }catch(Exception e){
            Log.e("log_tag", "Error converting result "+e.toString());
        }

        //try parse the string to a JSON object
        try{
                jArray = new JSONObject(result);
        }catch(JSONException e){
            Log.e("log_tag", "Error parsing data "+e.toString());
        }

        return jArray;
    }

    private void runLongClick(int clickId){
        SharedPreferences favoriteChannels = getSharedPreferences("favorite_channels_list", 0);
        SharedPreferences.Editor favoriteChannelsEditor = favoriteChannels.edit();
        if (favoriteButton){        
            favoriteChannelsEditor.putString(radioNames[clickId], radioUrls[clickId]);
            Toast.makeText(this, radioNames[clickId]+" added to favorites", Toast.LENGTH_LONG).show();
            buttonChannelList.setEnabled(true);
            favoriteChannelsEditor.commit();
        }else{
            Toast.makeText(this, favoriteRadioNames[clickId]+" removed From favorites", Toast.LENGTH_LONG).show();
            favoriteChannelsEditor.remove(favoriteRadioNames[clickId]);     
            favoriteChannelsEditor.commit();
            showFavoriteChannelList();          
        }       
    }
    private void getFavoritChannels(){
        SharedPreferences favoriteChannels = getSharedPreferences("favorite_channels_list", 0);
        favoriteChannelsMap=favoriteChannels.getAll();
        int i=0;
        favoriteRadioNames = new String[favoriteChannelsMap.size()];
        favoriteRadioUrls = new String[favoriteChannelsMap.size()];
        Log.d("String Arrays",String.valueOf(favoriteRadioNames.length));
        for(String s : favoriteChannelsMap.keySet()){
            favoriteRadioNames[i]=s;
            favoriteRadioUrls[i]=favoriteChannelsMap.get(s).toString();
            i++;
            }
    }

    private void showChannelsList(){
        buttonChannelList.setText("Favorite Channels");
        ArrayAdapter<String> adapter;
        adapter = new ArrayAdapter<String>(this,R.layout.channels,R.id.channelList,radioNames);
        setListAdapter(adapter);
        ListView lv = getListView();
        lv.setOnItemLongClickListener(new OnItemLongClickListener(){
        public boolean onItemLongClick(AdapterView<?> arg0, View arg1,int row, long arg3) {
            runLongClick(row);
            return true;
           }});
        favoriteButton=!favoriteButton;
    }
    private void showFavoriteChannelList(){
        buttonChannelList.setText("Channel List");
        getFavoritChannels();
        ArrayAdapter<String> adapterFavorits;
        adapterFavorits = new ArrayAdapter<String>(this,R.layout.channels,R.id.channelList,favoriteRadioNames);
        setListAdapter(adapterFavorits);
        ListView lv = getListView();
        lv.setOnItemLongClickListener(new OnItemLongClickListener(){
        public boolean onItemLongClick(AdapterView<?> arg0, View arg1,int row, long arg3) {
            runLongClick(row);
            return true;
           }});
        favoriteButton=!favoriteButton;

    }
    public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {
        Log.d("Gesture","Gesture Aldi");
        // TODO Auto-generated method stub
        ArrayList<Prediction> predictions = mLibrary.recognize(gesture);
        // We want at least one prediction
        if (predictions.size() > 0) {
            Prediction prediction = predictions.get(0);
            // We want at least some confidence in the result
            if (prediction.score > 1.0) {
                // Show the spell
                Toast.makeText(this, String.valueOf(prediction.score), Toast.LENGTH_SHORT).show();
                stopPlaying();
            }
        }

    }

    public void getMeta(){
        Timer timer;
        timer = new Timer();
        while(!metaDataThreadStop){
        timer.schedule(new TimerTask() {
            public void run() {
                URL url;
                //Message msg = handler.obtainMessage();
                try {
                    Log.d("Metadatos","Dentro del try para obtener los metadatos");
                    url = new URL(selectedRadioUrl);
                    IcyStreamMeta icy = new IcyStreamMeta(url);

                    artist=icy.getArtist();
                    Log.d("artist",artist);
                    song=icy.getTitle();
                    Log.d("song",song);
                    handler.sendEmptyMessage(0);


                } catch (MalformedURLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

            }
        }, 0, 30000);}
        timer.cancel();
    } 

    private Handler handler = new Handler() {
         @Override
         public void handleMessage(Message msg) {
             if(artist.compareTo("")==0 || artist.compareTo("-")==0)
                artistView.setText("no artist info");
             else{
                artistView.setText(artist);
                Log.d("handler_artist",artist);
             }

             if(song.compareTo("")==0 || song.compareTo("-")==0)
                songView.setText("no song info");
             else{
                 Log.d("handler_song",song);
                songView.setText(song);
                }

         }
    };
     @Override
    public void onSaveInstanceState(Bundle savedInstanceState) {
         super.onSaveInstanceState(savedInstanceState);
         // your stuff or nothing
     }

     @Override
    public void onRestoreInstanceState(Bundle savedInstanceState) {
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T13:23:56+00:00Added an answer on May 29, 2026 at 1:23 pm

    The stack trace says that player is null.

    02-13 02:42:52.106: E/AndroidRuntime(874): Caused by: java.lang.NullPointerException
    02-13 02:42:52.106: E/AndroidRuntime(874):  at com.beanie.samples.streaming.HomeActivity.onPause(HomeActivity.java:439)
    
    @Override
    protected void onPause() {
        super.onPause();
        if (player.isPlaying()) {
            player.stop();
        }
    }
    

    You apparently only initialize player for the case where mediaType is 2. Otherwise, you’re initializing aacPlayer.

    private void initializeMediaPlayer() {
        switch(mediaType){
        case 1:
            aacPlayer = new AACPlayer();
            break;
        case 2:
            player = new MediaPlayer();       
            ...
    

    So, you need a null check on player. Or, refactor your code to encapsulate the existence of two different media players.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two activities. In first I come to the second activity from first
If I have two activities in my app, one with listview and the other
This is my situation. I have two activities: ONE and TWO. In TWO activity
Its possible to retain a Fragment between Activities? Lets say I have Activity A
Lets say we have activities A, B. A starts B and passes an Intent
Lets say I have three Activities in my App. 1) Signup Activity 2) AccountActivate
I have a ListView with let's say 5 items. When I click on one
I have 2 activities. The first activity is an activity that parses JSON data
Ill first tell you what I am doing. I have three activities in the
Lets say we have a main class with 5 buttons, where when each clicked

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.