当开始新活动时,会打开空白活动

时间:2022-02-14 21:12:52

I am using this library for multiple image selection. After the user finish selecting the photos, another activity (current_location.class) should start.

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

Here is my code to do that:

我的代码是:

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

new activity is successfully started but its blank!

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

Below is my currentLocation.java Activity:

下面是我的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);
    }
}

and here is the current_location.xml:

这是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>

it should have background color, I tried adding buttons as well, but I always get blank activity started

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

is the problem from the way I am starting new activity? or from the way I am setting the xml layout to the currentLocation class?

问题是来自我开始新活动的方式吗?或者从我设置xml布局到currentLocation类的方式?

3 个解决方案

#1


3  

try changing your onCreate method. use the following instead:

尝试更改onCreate方法。使用以下:

@Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.current_location);
    }

#2


2  

Replace Intent intent = new Intent(getActivity(), currentLocation.class);
with
Intent intent = new Intent(this.getActivity(), currentLocation.class);

替换意图=新的意图(getActivity(), currentLocation.class);意图意图=新意图(this.getActivity(), currentLocation.class);


Also Check if <activity android:name=".currentLocation"> is there in manifest.

还要检查 在manifest中。

#3


0  

Maybe it doesn't matter but I would've tried two things to lower the chance of an error.

也许这无关紧要,但我可以尝试两件事来降低出错的几率。

  1. I would use putStringArrayListExtra() on the intent if you get an StringArrayListExtra from the activity result data intent

    如果您从活动结果数据意图获得StringArrayListExtra,那么我将在意图上使用putStringArrayListExtra()

  2. I would work with the specific activity/fragment context when creating the new intent.
    E.g. new Intent(className.this, currentLocation.class);
    OR new Intent(className.this.getActivity(), currentLocation.class);

    在创建新意图时,我将使用特定的活动/片段上下文。例如新意图(类名。这一点,currentLocation.class);或新意图(className.this.getActivity(),currentLocation.class);

#1


3  

try changing your onCreate method. use the following instead:

尝试更改onCreate方法。使用以下:

@Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.current_location);
    }

#2


2  

Replace Intent intent = new Intent(getActivity(), currentLocation.class);
with
Intent intent = new Intent(this.getActivity(), currentLocation.class);

替换意图=新的意图(getActivity(), currentLocation.class);意图意图=新意图(this.getActivity(), currentLocation.class);


Also Check if <activity android:name=".currentLocation"> is there in manifest.

还要检查 在manifest中。

#3


0  

Maybe it doesn't matter but I would've tried two things to lower the chance of an error.

也许这无关紧要,但我可以尝试两件事来降低出错的几率。

  1. I would use putStringArrayListExtra() on the intent if you get an StringArrayListExtra from the activity result data intent

    如果您从活动结果数据意图获得StringArrayListExtra,那么我将在意图上使用putStringArrayListExtra()

  2. I would work with the specific activity/fragment context when creating the new intent.
    E.g. new Intent(className.this, currentLocation.class);
    OR new Intent(className.this.getActivity(), currentLocation.class);

    在创建新意图时,我将使用特定的活动/片段上下文。例如新意图(类名。这一点,currentLocation.class);或新意图(className.this.getActivity(),currentLocation.class);