Estou desenvolvendo um app multitelas e quando clico no botão search o app fecha, porém quando clico em outro botão que também muda de atividade funciona bem. Os codigos dos botões são praticamente os mesmos.
MainActivity.java
package com.example.android.musicapp;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//If you to click in ImageView you go to Screen Playing
ImageView imageEvolve = (ImageView) findViewById(R.id.image_view_evolve);
imageEvolve.setOnClickListener(new View.OnClickListener() {
// The code in this method will be executed when the numbers View is clicked on.
@Override
public void onClick(View view) {
Intent imageEvolveIntent = new Intent(MainActivity.this, PlayingActivity.class);
startActivity(imageEvolveIntent);
}
});
//If you to click in TextView(Album name) you go to Screen Playing
TextView textAlbumEvolve = (TextView) findViewById(R.id.text_view_album_evolve);
textAlbumEvolve.setOnClickListener(new View.OnClickListener() {
// The code in this method will be executed when the numbers View is clicked on.
@Override
public void onClick(View view) {
Intent textAlbumEvolveIntent = new Intent(MainActivity.this, PlayingActivity.class);
startActivity(textAlbumEvolveIntent);
}
});
//If you to click in TextView(Artist name) you go to Screen Playing
TextView textArtistEvolve = (TextView) findViewById(R.id.text_view_artist_evolve);
textArtistEvolve.setOnClickListener(new View.OnClickListener() {
// The code in this method will be executed when the numbers View is clicked on.
@Override
public void onClick(View view) {
Intent textArtistEvolveIntent = new Intent(MainActivity.this, PlayingActivity.class);
startActivity(textArtistEvolveIntent);
}
});
//If you to click in icon profile you go to Screen Profile
Button buttonProfile = (Button) findViewById(R.id.icon_profile);
buttonProfile.setOnClickListener(new View.OnClickListener() {
// The code in this method will be executed when the numbers View is clicked on.
@Override
public void onClick(View view) {
Intent buttonProfileIntent = new Intent(MainActivity.this, ProfileActivity.class);
startActivity(buttonProfileIntent);
}
});
//If you to click in icon search you go to Screen Search
Button buttonSearch = (Button) findViewById(R.id.icon_search);
buttonSearch.setOnClickListener(new View.OnClickListener() {
// The code in this method will be executed when the numbers View is clicked on.
@Override
public void onClick(View view) {
Intent buttonSearchIntent = new Intent(MainActivity.this, SearchActivity.class);
startActivity(buttonSearchIntent);
}
});
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView
android:id="@+id/text_view_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Recently Played"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="#212121"
android:layout_marginLeft="16dp"
android:layout_marginBottom="12dp"
android:layout_marginTop="16dp"/>
<LinearLayout
android:id="@+id/linear_layout_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/text_view_title"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/image_view_evolve"
android:layout_width="144dp"
android:layout_height="144dp"
android:layout_marginBottom="8dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:src="@drawable/imagine_dragons_evolve"/>
<TextView
android:id="@+id/text_view_album_evolve"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:text="Evolve"/>
<TextView
android:id="@+id/text_view_artist_evolve"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:text="Imagine Dragons"/>
</LinearLayout>
</LinearLayout>
<TextView
android:id="@+id/text_msg_home"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginRight="16dp"
android:layout_marginLeft="16dp"
android:layout_below="@id/linear_layout_list"
android:text="@string/msg_home"
android:textColor="#C62828"/>
<RelativeLayout
android:id="@+id/relative_layout_menu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="12dp"
android:paddingBottom="12dp"
android:layout_alignParentBottom="true">
<Button
android:id="@+id/icon_home_selected"
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_centerHorizontal="true"
android:layout_marginRight="48dp"
android:layout_marginLeft="48dp"
android:background="@drawable/icon_home_selected"/>
<Button
android:id="@+id/icon_search"
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_toRightOf="@id/icon_home_selected"
android:background="@drawable/icon_search"/>
<Button
android:id="@+id/icon_profile"
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_toLeftOf="@id/icon_home_selected"
android:background="@drawable/icon_profile"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/relative_layout_player"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#512DA8"
android:paddingTop="12dp"
android:paddingBottom="12dp"
android:layout_above="@id/relative_layout_menu"
android:layout_marginBottom="6dp">
<TextView
android:id="@+id/text_music_player"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Believer"
android:textStyle="bold"
android:layout_marginLeft="16dp"
android:textColor="#ffffff"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Imagine Dragons"
android:textStyle="bold"
android:layout_below="@id/text_music_player"
android:layout_marginLeft="16dp"
android:textColor="#ffffff"/>
<Button
android:id="@+id/button_next"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_alignParentRight="true"
android:layout_marginRight="16dp"
android:layout_marginLeft="16dp"
android:layout_centerVertical="true"
android:background="@drawable/icon_next"/>
<Button
android:id="@+id/button_play"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_centerVertical="true"
android:layout_marginLeft="16dp"
android:layout_toLeftOf="@id/button_next"
android:background="@drawable/icon_play"/>
<Button
android:id="@+id/button_previous"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_centerVertical="true"
android:layout_toLeftOf="@id/button_play"
android:background="@drawable/icon_previous"/>
</RelativeLayout>