开始和活动后,活动结束

时间:2013-06-04 01:43:45

标签: android android-intent

所以我发布了一个更新,然后将其作为消息发送。当消息是我希望它返回到应用程序的主屏幕。我有我认为会这样做,但它只是快速打开其他活动然后关闭它并加载主屏幕。如何在完成发送消息后让活动返回到主屏幕活动。

 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);


}

2 个答案:

答案 0 :(得分: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);
        } 
    }
}

答案 1 :(得分: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();
}