Good afternoon guys, I need some help to better understand how to solve this error that appears in the finish:
I/Choreographer: Skipped 94 frames! The application may be doing too much work on its main thread.
I/Choreographer: Skipped 115 frames! The application may be doing too much work on its main thread.
E/libc++abi: terminating with uncaught exception of type std::bad_alloc: std::bad_alloc
Soon after the error of the frames appears the app is closed giving error. I wonder if anyone has gone through this before to help me.
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_radio_no_ar, container, false);
listViewPrograms = (ListView) rootView.findViewById(R.id.programacao_list);
am = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE);
afChangeListener = new AudioManager.OnAudioFocusChangeListener() {
@Override
public void onAudioFocusChange(int focusChange) {
if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT) {
stopPlaying();
} else if (focusChange == AudioManager.AUDIOFOCUS_LOSS) {
stopPlaying();
}
}
};
if (player != null) {
player.stop();
}
radioList = new Radio(getActivity()).getAll();
if (radioList.size() > 0) {
updateRadio();
mountView();
}
return rootView;
}
Play in stream:
private void startPlaying() {
if(urlStreaming == null) {
urlStreaming = objRadio.getStreaming();
}
player = new MediaPlayer();
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
threadRadio = Thread.currentThread();
threadRadio = new Thread(new Runnable() {
@Override
public void run() {
try {
player.setDataSource(urlStreaming);
} catch (IllegalArgumentException e) {
notifyErroPlayer();
} catch (SecurityException e) {
notifyErroPlayer();
} catch (IllegalStateException e) {
notifyErroPlayer();
} catch (IOException e) {
notifyErroPlayer();
}
try {
player.prepare();
final int result = focusOnPlay();
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED && player != null) {
player.start();
updateListPrograms();
shape = getDraw(getContext(), R.drawable.stop_button);
buttonPlay.setImageDrawable(shape);
setStateAudio(true);
}
}
});
} catch (IllegalStateException e) {
notifyErroPlayer();
} catch (IOException e) {
notifyErroPlayer();
}
}
});
threadRadio.start();
}
UpdateListPrograms which is where to start and causes the main thread error
private void updateListPrograms() {
final Handler handlerProgramacao = new Handler();
handlerProgramacao.post(new Runnable() {
@Override
public void run() {
inittask = new InitTask();
inittask.execute();
}
});
}