为什么mvvmcross在调用StartActivityForResult时关闭当前活动?

时间:2016-12-14 19:35:21

标签: android xamarin mvvmcross

我是移动跨平台开发的新手。我正在使用Xamarin和Mvvmcross创建一个应用程序。

我目前面临的问题是,当我想要打开蓝牙,请求调用StartActivityForResult()时,我的活动活动正在关闭,点击后对话框活动没有显示回来。

当我之前在一个简单的Xamarin.Android应用程序上使用此方法时,它按预期工作,显示启用蓝牙的对话框请求,同时活动仍处于活动状态。

当我使用Intent启动活动以通过内置邮件应用程序发送电子邮件时,也会发生类似的问题。发送电子邮件后,我没有被重定向到我的申请,我的申请被暂停。

这是我的方法:

 [Activity(NoHistory = true, ScreenOrientation = ScreenOrientation.Portrait)]
    public class MainView : MvxAppCompatActivity
    {
       ...
       protected override void OnViewModelSet()
       {
            base.OnViewModelSet();
            ...
            var bluetoothAdapter = BluetoothAdapter.DefaultAdapter;

            if(!bluetoothAdapter.IsEnabled)
               RequestEnableBluetooth();
            ...
       }
       public void RequestEnableBluetooth()
       {
           Intent turnOnBtIntent = new       
                 Intent(BluetoothAdapter.ActionRequestEnable);
           StartActivityForResult(turnOnBtIntent, 0);
       }
       ...
    }

1 个答案:

答案 0 :(得分:2)

MvvmCross没有那样做。 Android就是这样做的。它并不能保证您的活动在进入后台时仍然存在,它可能会随时将其删除。

但是,您的问题是,您在 <EditText android:id="@+id/password" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="@string/prompt_password" android:imeActionId="@+id/login" android:imeActionLabel="@string/action_sign_in_short" android:imeOptions="actionUnspecified" android:inputType="textPassword" android:maxLines="1" /> <Button android:id="@+id/forgot_password" android:layout_marginTop="8dp" android:text="@string/forgot_password" android:layout_gravity="end" android:typeface="normal" android:textSize="14sp" style="@style/Widget.AppCompat.Button.Borderless" android:background="@drawable/tw__transparent" android:layout_height="38dp" android:layout_width="130dp" /> <Button android:id="@+id/email_sign_in_button" style="?android:textAppearanceSmall" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="8dp" android:text="@string/action_sign_in" android:background="@drawable/rounded_corners" android:textSize="18sp" /> </LinearLayout> <LinearLayout android:id="@+id/facebook_login" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="bottom" android:orientation="horizontal"> <com.facebook.login.widget.LoginButton android:id="@+id/facebook_login_button" android:layout_width="match_parent" android:layout_height="wrap_content"/> </LinearLayout> </LinearLayout> </ScrollView> <ProgressBar android:id="@+id/login_progress" style="?android:attr/progressBarStyleLarge" android:layout_width="wrap_content" android:layout_height="wrap_content" android:visibility="gone" /> 上使用NoHistory = true这样,当导航离开时,没有人可以返回此Activity