我在MainActivity中有这段代码.java
FloatingActionButton fab2 = findViewById(R.id.fab2);
fab2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
// "mailto","info@jmremovals.com.au", null));
//tartActivity(Intent.createChooser(emailIntent, "Send email..."));
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
String shareBody = "Here is the share content body";
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject Here");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
startActivity(Intent.createChooser(sharingIntent, "Share via"));
CompletedFrag compFrag = new CompletedFrag();
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction transaction = fm.beginTransaction();
transaction.replace(R.id.nav_host_fragment, compFrag);
transaction.commit();
}
});
现在它会显示共享应用程序屏幕并更改片段,但如果我决定不共享应用程序,我仍然会更改片段。
所以我的问题是我可以执行与上述相同的过程,但如果他们在不共享应用程序的情况下取消(通过提供的选项(,那么它会返回到上一个片段,我想也许是一个 if else 语句,但我是 android 的新手,不知道它会怎么做!
非常感谢您的帮助!
经过多次搜索,我发现没有解决方案(我知道(可以做到我所要求的,因为它是由 android 系统本身处理的,而且这些东西是锁紧的。 如果您试图阻止某人访问页面,除非有所作为,那么我建议您看看您正在寻找的内容是否可以通过网站或类似方式完成。
我最终放弃了这条路,走上了一条不同的道路,即使我能够停止更改片段,如果他们不分享给另一个人,他们也可以分享给自己并继续。
希望这可能会对某人有所帮助。