2013-05-14 16 views
0

我發送一封電子郵件,但當用戶從電子郵件作曲者回來時,我需要轉到其他活動,如何完成此操作?android如何使用startActivityForResult從郵件作曲者回來後執行操作

這裏我的代碼, //發送郵件

String prestartTypeString = prestartType; 
String to = "[email protected]"; 
String subject = "Pre-Start - "+prestartTypeString; 
String message = fullName+" has sent you a Pre-Start checklist for equipment " 
        +registrationNumber+".\n" + "Please find PDF report attached. 
    \n\nNeed help viewing this report\nEmail us anytime at\[email protected]"; 

Intent email = new Intent(Intent.ACTION_SEND); 
email.putExtra(Intent.EXTRA_EMAIL, new String[]{ to}); 

email.putExtra(Intent.EXTRA_SUBJECT, subject); 
email.putExtra(Intent.EXTRA_TEXT, message); 

//attachment 
Uri uri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(), 
                   "generato.pdf")); 
email.putExtra(Intent.EXTRA_STREAM, uri); 

//need this to prompts email client only 
email.setType("message/rfc822"); 

startActivity(Intent.createChooser(email, "Choose an Email client :")); 

setResult(RESULT_OK, email); 

我已經檢查

startActivityForResult();

,但不具有明確的,如果這是爲了做到這一點,並沒有使其工作

因此當用戶從電子郵件意圖回來如何觸發功能?

謝謝

回答

1

用startActivityForResult()開始活動;並重寫下列方法

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    // TODO Auto-generated method stub 
    super.onActivityResult(requestCode, resultCode, data); 
      //place your code here what you want to do when result is returned, in your case go to different activity 
} 

調用此方法時,稱爲活動返回結果

+0

它不是爲我工作 – asiya 2014-06-30 07:58:55

相關問題