I'm building a music player in android. What I'm trying is to show playlist when the app launches and user click on the list item and intent is passed to the android_player activity which plays the song. But it's not working and when i click on list item app crashes and closes.
But when I declare music_player activity as launcher it works. But I want to show the playlist first and not the music_player.
I have following manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.app"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".AndroidMusicPlayerActivity"
android:label="@string/app_name"
android:configChanges="keyboardHidden|orientation"
android:screenOrientation="portrait">
<-- <intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter> -->
</activity>
</application>
What changes I should make to my manifest file to make it work.
AndroidMusicPlayerActivity has following code to receive intent
@Override
protected void onActivityResult(int requestCode,
int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(resultCode == 100){
currentSongIndex = data.getExtras().getInt("songIndex");
// play selected song
playSong(currentSongIndex);
}
}
MainActivity which shows playlist passes following intent
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// getting listItem index
int songIndex = position;
// Starting new intent
Intent in = new Intent(getApplicationContext(),
AndroidMusicPlayerActivity.class);
// Sending songIndex to PlayerActivity
in.putExtra("songIndex", songIndex);
setResult(100, in);
// Closing PlayListView
finish();
}
});
Log Cat data, when I click on listitem.
04-30 16:17:16.946: D/OpenGLRenderer(3858): Enabling debug mode 0 04-30
16:17:29.958: W/IInputConnectionWrapper(3858): showStatusIcon on inactive InputConnection
04-30 16:17:30.018: D/OpenGLRenderer(3858): Flushing caches (mode 0)
What changes I should make to make this code work. I'm new to android. Please help. Thanks!!
I may be missing something but in your itemClickListener you seem to be calling finish() on your first activity without starting the second. Surely you need to add a startActivity(in); call.