我想給用戶分享cardview內容的選項。 我使用的主要活動這個代碼,它工作正常:如何從CardView開始分享行動的新活動
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
String shareBody = "some text to share";
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject Here");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
startActivity(Intent.createChooser(sharingIntent, "Share via"));
但是當我從recyclerview使用相同的代碼,收到錯誤和應用程序崩潰。
從一個活動上下文之外調用startActivity()需要
FLAG_ACTIVITY_NEW_TASK標誌: 也我通過添加FLAG和仍然沒有工作
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
String shareBody = " teext to be shared";
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject Here");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
sharingIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(Intent.createChooser(sharingIntent, "Share via"));
IAM收到這個錯誤修改的代碼。這真的是你想要的嗎?
holder.iconFavorites_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// IAM這裏調用代碼和代碼塊位於適配器類的內部爲recycleview ....位於內側onBindViewHolder代碼mithod } });
任何機構都有解決這個問題的辦法嗎?如果有任何信息需要告訴我
發佈錯誤跟蹤。 – fluffyBatman
您需要明白,每行代碼可能看起來都不錯。這些問題通常會在您將這些線路混合在一起以形成邏輯過程時出現。從你給的信息是不可能幫助你。發佈代碼以顯示您如何在RecyclerView中實施共享操作 – Marat
當您沒有發佈任何與應用程序崩潰相關的錯誤或任何內容時,您希望人們如何幫助您? – deathangel908