I am using a REST client in Android. I saw an example of using Service to connect to the server and ResultReceiver to notify that the operation was completed. I call the service from a fragment, and if I try to rotate the screen while the service is running, the getActivity () method in ResultReceiver returns null, because maybe this fragment is no longer in the layout.
Fragment callback method:
@Override public void onReceiveResult(int resultCode, Bundle resultData) { Response response = (Response) resultData .getSerializable(RestService.RESULT); if (resultCode == RestService.SUCCESS && response != null) { if (getActivity() != null) { recommendationResponse = response; getLoaderManager().restartLoader(0, new Bundle(), Fragment.this); } } }
getActivity() returns null. This is normal? What approach can be used to enable notification even when the screen is rotated? Local broadcast?
android rest service
Matroska Jun 07 '12 at 7:16 2012-06-07 07:16
source share