2012-11-29 86 views
5

結果我開發一個應用程序,應該返回一些文本,以啓動該意圖的應用程序。啓動活動從IME

但是啓動的意圖應用程序是一個IME /軟鍵盤。 因此,StartActivityForResult不可用,因爲IME是一項服務。

我該如何做到這一點?

我走到這一步:

鍵盤:

final Intent intent = new Intent("com.example.helloworld.GETTEXT"); 
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK); 
intent.putExtra("keyboard", true); 
startActivity(intent); 

其他應用程序:

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    Bundle extras = getIntent().getExtras(); 
    if (extras == null){     
     return; 
    } else { 
     finish(); 
    } 
} 

@Override 
public void finish() { 
    Intent data = new Intent(); 
    data.putExtra("test", "PASSED"); 
    setResult(RESULT_OK, data); 
    super.finish(); 
} 
+0

你不能使用這個廣播接收器? –

回答

0

你可以使用一個ResultReceiver因爲這是思考。

ResultReceiver lReceiver = new KeyboardResultReceiver(aListener); 
final Intent intent = new Intent("com.example.helloworld.GETTEXT"); 
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK); 
intent.putExtra(EXTRA_RESULT_RECIEVER, lReceiver); 
intent.putExtra("keyboard", true); 
startActivity(intent); 

private static final class KeyboardResultReceiver extends ResultReceiver { 

    public FileUploadResultReceiver() { 
    } 

    @Override 
    protected void onReceiveResult(int aResultCode, Bundle aResultData) { 
      //Do your thing here you can also use the bundle for your data transmission 
    } 
} 
1

您可以使用ResultReceiver。 看this example,這是很清楚的說明了它是如何工作的。