我与Branch.io进行了深层链接,但我在Android实现中遇到了一个奇怪的崩溃。
以下是重现问题的步骤:
如果应用程序已安装并使用深层链接启动,则似乎只会发生这种情况。如果未安装该应用程序,并且必须在单击深层链接时安装该应用程序,则不会发生此行为。
除了已经很奇怪的行为之外,我无法弄清楚它在哪里崩溃。这是崩溃日志:
03-10 16:13:21.215 13901-13901/com.xxxx.videocollaboration.app E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to destroy activity {com.xxxx.videocollaboration.app/com.xxxx.videocollaboration.app.activities_fragments.CXMainActivity}: java.lang.IllegalArgumentException: No view found for id 0x7f0b0088 (com.xxxx.videocollaboration.app:id/fragment_container) for fragment CXStartupFragment{42193e78 #0 id=0x7f0b0088}
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3337)
at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3355)
at android.app.ActivityThread.access$1300(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1290)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4921)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalArgumentException: No view found for id 0x7f0b0088 (com.xxxx.videocollaboration.app:id/fragment_container) for fragment CXStartupFragment{42193e78 #0 id=0x7f0b0088}
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1293)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1528)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1595)
at android.support.v4.app.FragmentManagerImpl.dispatchReallyStop(FragmentManager.java:2915)
at android.support.v4.app.FragmentController.dispatchReallyStop(FragmentController.java:249)
at android.support.v4.app.FragmentActivity.onReallyStop(FragmentActivity.java:816)
at android.support.v4.app.FragmentActivity.doReallyStop(FragmentActivity.java:795)
at android.support.v4.app.FragmentActivity.onDestroy(FragmentActivity.java:388)
at android.support.v7.app.AppCompatActivity.onDestroy(AppCompatActivity.java:209)
at com.xxxx.videocollaboration.app.activities_fragments.CXMainActivity.onDestroy(CXMainActivity.java:294)
at android.app.Activity.performDestroy(Activity.java:5352)
at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1124)
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3324)
at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3355)
at android.app.ActivityThread.access$1300(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1290)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4921)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
at dalvik.system.NativeStart.main(Native Method)
这是我的清单:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xxxxxx.videocollaboration.app"
android:versionCode="163"
android:versionName="2.8.1 (163)" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-feature android:name="android.hardware.camera" android:required="true" />
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />
<uses-feature android:name="android.hardware.telephony" android:required="false"/>
<application
android:name=".main.CXApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<!-- Branch.io values -->
<!-- <meta-data android:name="io.branch.sdk.TestMode" android:value="true" /> -->
<meta-data android:name="io.branch.sdk.BranchKey" android:value="@string/branch_key" />
<receiver android:name="io.branch.referral.InstallListener" android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
<activity
android:name=".activities_fragments.CXMainActivity"
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize"
android:windowSoftInputMode="adjustPan">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<data android:scheme="@string/branch_uri_scheme" android:host="@string/branch_host" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
<meta-data
android:name="io.fabric.ApiKey"
android:value="xxxxxxxxxxxx" />
<service
android:name=".services.NetworkTestService"
android:exported="false"/>
<service
android:name=".services.CXFileUploadService"
android:exported="false"/>
</application>
这是我主要活动中的onStart menthod:
@Override
protected void onStart()
{
super.onStart();
// Configure Branch.io
initiatedBranchDeepLinks = true;
Branch branch = Branch.getInstance();
branch.initSession(new Branch.BranchReferralInitListener(){
@Override
public void onInitFinished(JSONObject referringParams, BranchError error) {
if (error == null) {
// params are the deep linked params associated with the link that the user clicked -> was re-directed to this app
// params will be empty if no data found
// ... insert custom logic here ...
String message = "Branch.io onInitFinished. Params: " + referringParams.toString();
Log.d(TAG, message);
String databaseGUID = referringParams.optString(LINK_PARAM_DATABASE_GUID);
String conferenceCode = referringParams.optString(LINK_PARAM_CONFERENCE_CODE);
if(!CXStringUtils.isNullOrBlank(databaseGUID)) {
CXAppConfig.getSharedInstance().setTargetDatabaseGUID(databaseGUID);
}
if(!CXStringUtils.isNullOrBlank(conferenceCode)) {
CXAppConfig.getSharedInstance().setConferenceCode(conferenceCode);
}
ApiService apiService = ApiService.getInstance();
apiService.get(CXMainActivity.this, ApiCall.GET_ENVIRONMENT_INFO_GET, new HashMap<String, String>(), HashMap.class, initCallBack);
} else {
Log.i(TAG, error.getMessage());
}
}
}, this.getIntent().getData(), this);
}
更新:当应用程序重新启动时,它会在initSession调用时崩溃。