开始新活动时,我打开了空白活动

Sou*_*rce 2 xml android android-intent android-activity android-studio

我正在使用这个库进行多个图像选择。用户选择完照片后,current_location.class应启动另一个活动 ( )。

这是我的代码:

public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == OPEN_MEDIA_PICKER) {
            // Make sure the request was successful
            if (resultCode == RESULT_OK && data != null) {
                selectionResult = data.getStringArrayListExtra("result");
                Intent intent = new Intent(getActivity(), currentLocation.class);
                intent.putExtra("selectedMedia", selectionResult);
                startActivity(intent);
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

新活动已成功启动,但它是空白的!

以下是我的currentLocation.java 活动:

public class currentLocation extends AppCompatActivity {

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState, @Nullable PersistableBundle persistentState) {
        super.onCreate(savedInstanceState, persistentState);
        setContentView(R.layout.current_location);
    }
}
Run Code Online (Sandbox Code Playgroud)

这是current_location.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/bg_view">
    
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

它应该有背景颜色,我也尝试添加按钮,但我总是开始空白活动

问题出在我开始新活动的方式上吗?还是从我将xml布局设置为currentLocation班级的方式?

Beh*_*ahi 11

尝试改变你的onCreate方法。请改用以下内容:

@Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.current_location);
    }
Run Code Online (Sandbox Code Playgroud)