仅当他们按意图完成时才更改片段(在这种情况下他们实际上共享应用程序)
Change Fragments Only If They Go Through With The Intent (They Acually Share The App In This Case)
我在 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();
}
});
现在它会显示共享应用程序屏幕并更改片段,但如果我决定不共享该应用程序,我仍然会更改片段。
所以我的问题是我可以执行与上面相同的过程但是如果他们在不共享应用程序的情况下取消(通过提供的选项)那么它 returns 到上一个片段我认为可能是一个 if else 语句但是我是 android 的新手,不知道它是怎么做到的!
非常感谢您的帮助!
经过大量搜索,我发现没有(我知道的)解决方案可以满足我的要求,因为它是由 android 系统本身处理的,而且这些东西是锁紧的。
如果您试图阻止某人访问页面,除非已完成某些操作,那么我建议您查看是否可以通过网站或类似网站完成您正在寻找的内容。
我最终放弃了这条路,走上了另一条路,因为即使我能够停止更改片段,如果他们不分享给另一个人,他们也可以自己分享并继续。
希望这对某人有所帮助。
我在 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();
}
});
现在它会显示共享应用程序屏幕并更改片段,但如果我决定不共享该应用程序,我仍然会更改片段。
所以我的问题是我可以执行与上面相同的过程但是如果他们在不共享应用程序的情况下取消(通过提供的选项)那么它 returns 到上一个片段我认为可能是一个 if else 语句但是我是 android 的新手,不知道它是怎么做到的!
非常感谢您的帮助!
经过大量搜索,我发现没有(我知道的)解决方案可以满足我的要求,因为它是由 android 系统本身处理的,而且这些东西是锁紧的。 如果您试图阻止某人访问页面,除非已完成某些操作,那么我建议您查看是否可以通过网站或类似网站完成您正在寻找的内容。
我最终放弃了这条路,走上了另一条路,因为即使我能够停止更改片段,如果他们不分享给另一个人,他们也可以自己分享并继续。
希望这对某人有所帮助。