如何使用xamarin.forms中另一个活动的上次访问内容页面打开父活动?

时间:2017-10-21 13:40:00

标签: android xamarin android-activity xamarin.forms xamarin.android

我在xamarin.forms工作。我陷入了Android的活动导航。

我的整个申请工作都是Activity MainActivity。 在我的一个内容页面中,我想打开包含所有联系人列表的联系人应用程序。

我创建了另一个活动,并使用依赖关系服务(如下面的代码)从内容页面开始按钮点击活动。

var intent = new Intent(Forms.Context, typeof(ContactApplicationActivity));
Forms.Context.StartActivity(intent);

OnCreate的{​​{1}}方法我转到联系人应用程序。当用户点击任何联系ContactApplicationActivity方法调用并打开邮件和电子邮件默认应用程序时。

ContactApplicationActivity.cs:

OnActivityResult

一切都很好。但问题是从public class ContactApplicationActivity : Activity { public object smsTask { get; private set; } protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); var contactPickerIntent = new Intent(Intent.ActionPick, Android.Provider.ContactsContract.Contacts.ContentUri); StartActivityForResult(contactPickerIntent, 101); } protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) { if (InviteFriends.IsSMS && !InviteFriends.IsEmail) { if (requestCode == 101 && resultCode == Result.Ok) { //Ensure we have data returned if (data == null || data.Data == null) return; var addressBook = new Xamarin.Contacts.AddressBook(this); addressBook.PreferContactAggregation = false; //Load the contact via the android contact id in the last segment of the Uri returned by the android contact picker var contact = addressBook.Load(data.Data.LastPathSegment); //Use linq to find a mobile number var mobile = (from p in contact.Phones where p.Type == Xamarin.Contacts.PhoneType.Mobile select p.Number).FirstOrDefault(); //See if the contact has a mobile number if (string.IsNullOrEmpty(mobile)) { Toast.MakeText(this, "No Mobile Number for contact!", ToastLength.Short).Show(); return; } else { if (CrossMessaging.Current.SmsMessenger.CanSendSms) { CrossMessaging.Current.SmsMessenger.SendSms(mobile, "My Message"); } } } } else if (!InviteFriends.IsSMS && InviteFriends.IsEmail) { //Ensure we have data returned if (data == null || data.Data == null) return; var addressBook = new Xamarin.Contacts.AddressBook(this); addressBook.PreferContactAggregation = false; //Load the contact via the android contact id in the last segment of the Uri returned by the android contact picker var contact = addressBook.Load(data.Data.LastPathSegment); //Use linq to find a mobile number var emailid = (from p in contact.Emails where p.Type == Xamarin.Contacts.EmailType.Home select p.Address).FirstOrDefault(); //See if the contact has a mobile number if (string.IsNullOrEmpty(emailid)) { Toast.MakeText(this, "No Email for contact!", ToastLength.Short).Show(); return; } else { var email = BuildSampleEmail(emailid, true).Build(); if (CrossMessaging.Current.EmailMessenger.CanSendEmail) { CrossMessaging.Current.EmailMessenger.SendEmail(email); } } } } public static EmailMessageBuilder BuildSampleEmail(string ToEmailId, bool sendAsHtml = false) { //var builder = new EmailMessageBuilder() // .To(ToEmailId) // .Cc("cc.plugins@xamarin.com") // .Bcc(new[] { "bcc1.plugins@xamarin.com", "bcc2.plugins@xamarin.com" }) // .Subject("eRecall App"); var builder = new EmailMessageBuilder() .To(ToEmailId) .Subject("ABC"); if (sendAsHtml) builder.BodyAsHtml("<b>My Message </b>"); return builder; } } 活动打开联系人应用程序。 ContactApplicationActivity在后​​台。当我尝试从后台模式打开我的原始应用程序时。它打开时带有标题MainActivity的空白屏幕。当我按下后退按钮ContactApplicationActivity时,我的上一个内容页面已打开。

我想打开MainActivity的最后一个内容页面,没有任何空白屏幕

是否可以使用MainActivity解决问题?

0 个答案:

没有答案