android - 无论用于启动它的方法如何,Android 活动都不会启动
问题描述
我已经定义了一个 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>
我尝试在此活动的第一行onCreate
和Log
行中放置一个断点,但此活动无法启动。我认为活动的源代码是无关紧要的,因为它永远不会开始。如果需要,请告诉我。我尝试将另一个活动设置为默认活动并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
和覆盖onCreate
和onActivityResult
。
编辑:这是活动代码:
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");
}
});
}
}
解决方案
我看到了问题。你正在使用
public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState)
代替
protected void onCreate(@Nullable Bundle savedInstanceState)
你覆盖了错误的方法。
推荐阅读
- angular - 我无法使用我的项目 npm run sample 运行此命令
- javascript - Use maps.googleapi.com with "same-origin" cross origin policy
- image - 带有自动表 addImage 的 JSPDF
- python - Pytest:runtimeerror 线程“主线程”中没有当前事件循环
- email - 团队不显示通过 SendGrid 发送的电子邮件
- python - 模块“sib_api_v3_sdk”没有属性“SMTPApi”
- yaml - 如何在 github 操作中使用 terraform 解密 Iam_user 的 pgp 密钥
- excel - 使用 VBA 更改粘贴特殊设置
- python - Python/Pandas:如何从数据框的列中删除诸如 MR.、MS.、MISS 之类的称呼
- pdf - 签名后 PDF 损坏