c# - 当应用程序开始共享时如何调用旧意图?
问题描述
我想解释我的应用程序逻辑。我的应用程序正在查看 PDF。有两种显示 pdf 的方法。
用户登录应用程序并单击“显示 PDF”按钮。然后,App 会打开一个新窗口,用户选择一个 pdf 文件进行查看。
用户从他的手机存储中打开一个 pdf 并将该 pdf 共享给我的应用程序。(如果用户之前没有登录过应用,应用会打开登录页面。)
第一个工作正常。但是当用户从他的手机存储中向我的应用程序共享一个 pdf 文件时,应用程序会自动打开我的 HomePape。
应用中有 2 个公共 LoginPage(){}。
1.公共登录页面()
2.公共登录页面(字符串_pdfUri)
第一个允许用户登录应用程序。第二个,如果用户没有登录应用程序并将 pdf 共享给应用程序。通过这种方式,应用程序获取 pdfpath 并打开 PdfShowPage。
让我们检查代码,
应用程序.xaml.cs:
/* 我调试了这个。即使用户共享 Pdf,应用程序也总是会出现在这里。因此,PdfShowPage LoginPage 有效,而 LoginPage(string _pdfUri) 无效。该应用程序打开主页。基本上;
LoginPage() -> 主页
LoginPage(string _pdfUri) -> PdfShowPage
*/
public App()
{
InitializeComponent();
MainPage = new NavigationPage(new LoginPage())
{
BarBackgroundColor = Color.FromHex("008000"),
BarTextColor = Color.FromHex("E8E8E8")
};
}
protected override void OnStart()
{
// Handle when your app starts
}
protected override void OnSleep()
{
// Handle when your app sleeps
}
protected override void OnResume()
{
// Handle when your app resumes
}
MainActivity.cs,
protected override async void OnCreate(Bundle savedInstanceState)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(savedInstanceState);
ZXing.Net.Mobile.Forms.Android.Platform.Init();
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
LoadApplication(new App());
Share();
}
private void Share()
{
//Some codes for share
Navigate(path);
}
public async void Navigate(string path)
{
await Xamarin.Forms.Application.Current.MainPage.Navigation.PushModalAsync(new LoginPage(path));
}
登录页面.cs,
public LoginPage(string _pdfUri)
{
this.PdfUri = _pdfUri;
CheckSessionWithUri(_pdfUri); //it checks session and send pdf path to PDFshowPage.
}
public LoginPage()
{
CheckSession(); //it sends user to the HomePage if the user correctly login or the user has login before.
}
我想控制用户何时将 pdf 共享到我的应用程序,该应用程序必须将他发送到 PdfShowPage。我们应该在 App.xaml.cs 还是其他地方控制它?
谢谢。
解决方案
也许你可以通过_pdfUri
toApp
类,然后LoginPage
在_pdfUri
. 喜欢:
protected override async void OnCreate(Bundle savedInstanceState)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(savedInstanceState);
ZXing.Net.Mobile.Forms.Android.Platform.Init();
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
Share();
}
private void Share()
{
//Some codes for share
LoadApplication(new App(_pdfUri));
}
然后
public App(string _pdfUri)
{
InitializeComponent();
if(path !=null){
MainPage = new NavigationPage(new LoginPage(_pdfUri))
{
BarBackgroundColor = Color.FromHex("008000"),
BarTextColor = Color.FromHex("E8E8E8")
};
}else{
MainPage = new NavigationPage(new LoginPage())
{
BarBackgroundColor = Color.FromHex("008000"),
BarTextColor = Color.FromHex("E8E8E8")
};
}
}
推荐阅读
- javascript - 添加新行后 select2 如何在表中正常工作?
- java - 在 Maven 中创建具有外部依赖项和其他 jar 的 jar
- gnuplot - gnuplot 将框绘制到线条上
- machine-learning - 错误:在 GCP 上使用 AI Platform 训练模型时出现“参数 --job-dir:预期的一个参数”
- reactjs - 如何使用 ReactToPrint 插件在 pdf 中显示下拉选择的值?
- python - 自定义模板标签:将其实际放在模板中的什么位置?
- python - 访问表单中的 request.session['key'] 时出错。[使用 CheckboxSelectMultiple]
- javascript - Javascript 嵌套异常处理
- c++ - C++/libscreen 无法更新可见性
- html - 表单提交成功后如何通知显示