Reputation: 659
I have setup an activity to be executed from a menu button. The activity is started and briefly appears and then crashes. I have added added activity to manifest file. Code poseted below. I have recently switched form Eclipse to Android Studio and still learning the changes.
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<application
android:allowBackup="true"
android:icon="@mipmap/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=".Titles_Edit_Activity"
android:label="@string/title_activity_titles__edit_"
android:theme="@style/Theme.AppCompat">
</activity>
</application>
This is the logcat message: 08-13 11:13:45.841 15302-15302/com.example.jerry.els2015 D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
Menu trigger in MainActivity
public void setup(MenuItem menuItem){
Log.d("TAG", "Setting ");
startActivity(new Intent(this,Titles_Edit_Activity.class));
}
XML for Tiles_Edit_Activity
package com.example.jerry.els2015;
import android.app.Activity;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
public class Titles_Edit_Activity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_titles__edit_);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_titles__edit_, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
I found the issue on the activity. I setup menu and back button to finish and exit the system so bluetooth will be killed. I removed these option and was able to execute the new activity.
@Override
protected void onDestroy() {
super.onDestroy();
// finish();
// System.exit(0);
}
@Override
protected void onStop() {
super.onStop();
// finish();
// System.exit(0);
}
Upvotes: 1
Views: 58
Reputation: 659
I found the issue on the activity. I setup menu and back button to finish and exit the system so bluetooth will be killed. I removed these option and was able to execute the new activity.
@Override
protected void onDestroy() {
super.onDestroy();
finish();
System.exit(0);
}
@Override
protected void onStop() {
super.onStop();
// finish();
// System.exit(0);
}
Upvotes: 0
Reputation: 66
try other way for startactivity, ex;
Intent intent = new Intent(MainActivity.this, Titles_Edit_Activity.class);
startActivity(intent);
Upvotes: 1