2013-06-04 221 views
1

因此,我正在啓動更新並將其作爲消息發送。當消息是我希望它回到應用程序的主屏幕。我有我認爲會這樣做,但它只是快速打開其他活動,然後關閉它,並加載主屏幕。如何在完成發送消息後將活動返回到主屏幕活動。啓動和活動完成後活動

public void send(View view) 
{ 

    savePhoto(); 
    Uri imageUri = Uri.fromFile(pictureFile); 
    Intent sendIntent = new Intent(Intent.ACTION_SEND); 
    sendIntent.setType("image/jpeg"); 
    sendIntent.putExtra(Intent.EXTRA_STREAM, imageUri); 
    close(); 
    //This activity opens and quickly closes 
    startActivity(Intent.createChooser(sendIntent, "Send:")); 
    startActivity(home); 


} 
+0

我不明白,如果你想回到以前的屏幕發送後,爲什麼要調用startActivity?爲什麼不完成()呢? –

回答

0

你所尋找的是startActivityForResult(ref):

private final static int MY_REQUEST_CODE = 0; 

public void send(View view) { 
    ... 
    startActivityForIntent(Intent.createChooser(sendIntent, "Send:")); 
} 


protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    if (requestCode == MY_REQUEST_CODE) { 
     if (resultCode == RESULT_OK) { 
      //You can check for any result set from request activity 
      //Set your own results using Activity.setResult(int); 
      startActivity(home); 
     } 
    } 
} 
+0

我剛剛複製並粘貼了你的'onActivityResult'代碼,但它仍然返回到前一個活動並調用onResume();' –

0

嘗試這個 -

public void send(View view) 
{ 

savePhoto(); 
Uri imageUri = Uri.fromFile(pictureFile); 
Intent sendIntent = new Intent(Intent.ACTION_SEND); 
sendIntent.setType("image/jpeg"); 
sendIntent.putExtra(Intent.EXTRA_STREAM, imageUri); 
close(); 
startActivity(Intent.createChooser(sendIntent, "Send:")); 
Intent i=new Intent(this,Home.class); 
startActivity(i); 
finish(); 
}