Tenho um botão no qual insere registro no metodo public boolean onOptionsItemSelected(MenuItem item) porem ao clicar no botao ele fecha o aplicativo todo. Quero que ele retorne a minha outra tela activity_lista.xml como corrigir ?
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="br.com.alura.agenda.FormularioActivity">
<item android:id="@+id/menu_formulario_ok"
android:title="Ok"
android:icon="@drawable/ic_confirmar"
app:showAsAction="always"/>
</menu>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.nicolle.cupfinal">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name">
</activity>
<activity
android:name=".Lista"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.item, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_formulario_ok:
Toast.makeText(MainActivity.this, "Aluno salvo!", Toast.LENGTH_SHORT).show();
finish();
break;
}
return super.onOptionsItemSelected(item);
}
}