So i have a simple Question , it is Possible to Handle the Method onActivityResult() in a Service if this Activity was Started from the Same Service (Using Intent) ?
In
Open Transparent activity from service and use BroadcastReceiver in service. Follow the steps in detail.
1. Open transparent activity from Service
Intent i = new Intent(mContext, FloatingServiceSupportActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.putExtra("action", "SpeechRegnition");
mContext.startActivity(i);
// For transparent activity use this code in AndroidManifest.xml
2. Create BroadcastReceiver in Service
BroadcastReceiver brOnActivityResult = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// TODO:
}
};
3. Register this broadcast in onCreate of Service
IntentFilter brintent = new IntentFilter();
brintent.addAction("brActionFloatingServiceOnActivityResult");
mContext.registerReceiver(brOnActivityResult, brintent);
4. Unregister this broadcast in onDestroy of Service
mContext.unregisterReceiver(brOnActivityResult);
5. Do work in Activity by using startActivityForResult and Send broadcast from Activity's (FloatingServiceSupportActivity) onActivityResult
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Intent i = new Intent();
i.setAction("brActionFloatingServiceOnActivityResult");
i.putExtra("action", "initTextToSpeech");
mActivity.sendBroadcast(i);
mActivity.finish();
}