Android Intent没有启动活动

时间:2016-11-17 15:20:46

标签: java android android-intent

我在启动startActivity(intent)以实际打开下一个活动时遇到问题。当我按下相关按钮时,它将字符串打印到调试控制台,但新活动才刚开始。我做错了什么。

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);
}
}

我的MainActivity。

这是我的清单。

<?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>

1 个答案:

答案 0 :(得分:1)

根据评论,您需要更改CameraOptions以扩展AppCompatActivity或Activity而不是MainActivity