ConnorB271 ConnorB271 - 16 days ago 6
Java Question

Android Intent not starting activity

I'm having issues getting startActivity(intent) to actually open the next activity. when I press the associated button it's printing the string to the debug console, but the new activity just isn't starting. Am I doing something wrong.

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

Button camBtn = (Button) findViewById(R.id.btnCamera);
camBtn.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view){
startCameraOption(view);
}
});

}

public void startCameraOption(View view){
Intent intent = new Intent(MainActivity.this, CameraOption.class);
intent.putExtra("Launcher","Launched.");
System.out.println("Starting next activity,");
startActivity(intent);
}
}


There's my MainActivity.

Here is my manifest.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.sample.cloudvision">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />


<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:screenOrientation="portrait"
android:name="com.google.sample.cloudvision.MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".CameraOption">
</activity>
<activity
android:name=".PictureChosenClass">
</activity>
</application>

</manifest>

Answer

Per comments you need to change CameraOptions to extend AppCompatActivity or Activity instead of MainActivity

Comments