无论启动哪种活动,Android活动都不会启动

时间:2018-10-30 10:15:49

标签: android android-activity startup

我已经定义了一个android活动,无论我尝试如何启动它都无法启动。它应该作为主要活动启动,但是如果我将其声明为默认活动,则该应用程序就会挂起:

    <activity
        android:name=".activity.StartupActivity"
        android:screenOrientation="portrait"
        android:theme="@style/NoActionAppTheme">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

            <data
                android:host="url"
                android:pathPrefix="/prefix"
                android:scheme="https" />
            <data
                android:host="url"
                android:scheme="https" />
        </intent-filter>
    </activity>

在此活动中,我尝试在onCreateLog的第一行放置一个断点,但是此活动并未开始。我认为该活动的源代码是irrelevent,因为它从未启动过。请让我知道是否需要。我尝试将另一项活动设置为默认活动,并像这样从其中开始StartupActivity

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (! AppRuntime.b) {
        AppRuntime.b = true;
        startActivity(new Intent(this, StartupActivity.class));
        finish();
        return;
    }
// other stuff
}

但是结果类似于StartupActivity是默认活动时看到的结果。此活动中的断点按预期工作。当StartupActivity启动时出现问题。是什么引起了这个问题?

注意:StartupActivity扩展了AppCompatActivity并仅覆盖onCreateonActivityResult

编辑:这是活动代码:

public class StartupActivity extends AppCompatActivity {

    SharedPreferences sp;
    String deepLink = "";

    final int SIGNUP_REQUEST_CODE = 0;
    final int TUTORIAL_REQUEST_CODE = 1;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState, @Nullable PersistableBundle persistentState) {
        super.onCreate(savedInstanceState);
        addressInvitation();

        sp = App.getSharedPreferences();

        MobileAds.initialize(this, Utils.getAdmobID());

        setContentView(R.layout.activity_splash_screen);
        //load the ad
//        mAdView = findViewById(R.id.adView);
//        AdRequest adRequest = new AdRequest.Builder().build();
//        mAdView.loadAd(adRequest);

        Log.d("DEBUGGING", "calling bootstrap");

        bootstrapApp();
    }


    private void bootstrapApp() {
        if (! sp.contains("signed_in")) {
            sp.edit().clear().apply();
            Log.d("DEBUGGING", "starting signup activity");
            startActivityForResult(new Intent(this, SignUp.class), SIGNUP_REQUEST_CODE);
        } else if (! sp.contains("isFirstTime")) {
            Log.d("DEBUGGING", "starting tutorial");
            startActivityForResult(new Intent(this, TutorialsActivity.class), TUTORIAL_REQUEST_CODE);
        } else {
            Log.d("DEBUGGING", "going to splash screen");
            startActivity(new Intent(this, SplashScreen.class));
            finish();
        }
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        switch (requestCode) {
            case SIGNUP_REQUEST_CODE:
                Log.d("DEBUGGING", "signup returned");
                if (resultCode == RESULT_OK) {
                    sp.edit()
                            .putBoolean("signed_in", true)
                            .apply();
                } else {
                    finish();
                }
                break;
            case TUTORIAL_REQUEST_CODE:
                Log.d("DEBUGGING", "tutorial returned");
                if (resultCode == RESULT_OK) {
                    sp.edit()
                            .putBoolean("isFirstTime", true)
                            .apply();
                } else {
                    finish();
                }
                break;
        }
        bootstrapApp();
    }



    private void addressInvitation() {
        FirebaseDynamicLinks.getInstance().getDynamicLink(getIntent())
                .addOnSuccessListener(this, new OnSuccessListener<PendingDynamicLinkData>() {
                    @Override
                    public void onSuccess(PendingDynamicLinkData data) {
                        if (data == null) {
                            return;
                        }

                        // Get the deep link
                        deepLink = data.getLink().toString();

                        // Extract invite
                        FirebaseAppInvite invite = FirebaseAppInvite.getInvitation(data);
                        if (invite != null) {
                            String invitationId = invite.getInvitationId();
                        }
                    }
                })
                .addOnFailureListener(this, new OnFailureListener() {
                    @Override
                    public void onFailure(@NonNull Exception e) {
                        Log.e("HandleInvitaiton", "COULD NOT HANDLE");
                    }
                });
    }
}

1 个答案:

答案 0 :(得分:2)

我看到了问题。您正在使用

public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState)

代替

protected void onCreate(@Nullable Bundle savedInstanceState)

您要覆盖错误的方法。