2013-10-02 15 views
0

我正在使用以下方法在用戶設備上生成文件,然後通過電子郵件將它發送給我。在Android片段中使用公共無效的onComplete(File outfile)方法

new ActivityDumpUtil(FragmentRequestIcons.this, outfile, new ActivityDumpUtil.ActivityDumpCallback() { 
       @Override 
       public void onComplete (File outfile) { 
        Intent intent = new Intent(android.content.Intent.ACTION_SEND); 
        intent.setType("text/plain"); 
        Uri uri = Uri.fromFile(outfile); 
        intent.putExtra(android.content.Intent.EXTRA_STREAM, uri); 
        intent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { "************" }); 
        intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Icon Support"); 
        intent.putExtra(android.content.Intent.EXTRA_TEXT, "I am using " + Build.DEVICE + " with Android version " + Build.VERSION.RELEASE + " on " + getResources().getString(R.string.app_name)); 
        startActivity(Intent.createChooser(intent, "Send eMail..")); 
        finish(); 
       } 
      }) 

我最近有這樣一個活動,但由於IM機器人會用抽屜式導航上午片段現在想要它。

當然finish()將不能在一個片段中工作。我怎樣才能從我的片段做出這項工作?

回答

0

使類serializable並與意圖。

要使類序列化:

class yourClass implements Serializable{} 

爲了把它與你的意圖:

intent.putExtra("The Class", this); 

爲了獲取類出意向的(在你的片段使用):

yourClass yc = (yourClass) getIntent().getExtras().getSerializable("The Class"); 
yc.finish()//use this whenever you want 
+0

我該怎麼辦呢? – Bignadad

+0

見編輯。但我認爲讓你的片段成爲一個片段活動更容易。 http://developer.android.com/reference/android/support/v4/app/FragmentActivity.html –

+0

我想過,但即時通訊使用導航抽屜。如果我這樣做,我將不得不重新加載導航抽屜。我以這種方式開始,但把所有東西都放在碎片中似乎是要走的路。我會嘗試你更新的答案。感謝您的回覆 – Bignadad