I followed this article and pieced together information with other articles to create a splash screen:
https://learn.microsoft.com/en-us/xamarin/android/user-interface/splash-screen
The splash screen works well when I start the app up by tapping on the app's icon. However, if the app is already running and I switch to it, the screen goes white for a few seconds while the app resumes. Why?
Here is my code:
[Activity(Label = "Hardfolio", Icon = "#drawable/icon", Theme = "#style/MyTheme.Splash", MainLauncher = true, NoHistory = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class SplashActivity : FormsAppCompatActivity
{
static readonly string TAG = "Hardfolio: " + typeof(SplashActivity).Name;
public override void OnCreate(Bundle savedInstanceState, PersistableBundle persistentState)
{
base.OnCreate(savedInstanceState, persistentState);
}
// Launches the startup task
protected override void OnResume()
{
base.OnResume();
var startupWork = new Task(AppStartup);
startupWork.Start();
}
// Simulates background work that happens behind the splash screen
async void AppStartup()
{
StartActivity(new Intent(Application.Context, typeof(MainActivity)));
}
}
[Activity(Label = "Hardfolio", Icon = "#drawable/icon", Theme = "#style/MainTheme", MainLauncher = false, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
[IntentFilter(new[] { UsbManager.ActionUsbDeviceAttached })]
[MetaData(UsbManager.ActionUsbDeviceAttached, Resource = "#xml/device_filter")]
public class MainActivity : Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
#region Fields
private AndroidHidDevice _TrezorHidDevice;
private UsbDeviceAttachedReceiver _UsbDeviceAttachedReceiver;
private UsbDeviceDetachedReceiver _UsbDeviceDetachedReceiver;
private object _ReceiverLock = new object();
#endregion
#region Overrides
protected override void OnCreate(Bundle bundle)
{
try
{
_TrezorHidDevice = new AndroidHidDevice(GetSystemService(UsbService) as UsbManager, ApplicationContext, 3000, 64, TrezorManager.TrezorVendorId, TrezorManager.TrezorProductId);
ServicePointManager.ServerCertificateValidationCallback += (o, certificate, chain, errors) => true;
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(bundle);
Xamarin.Forms.Forms.Init(this, bundle);
RegisterReceiver();
var application = new App(new CrossPlatformUtilities(new IsolatedStoragePersister(), new AndroidRESTClientFactory()), _TrezorHidDevice, GetPin);
LoadApplication(application);
}
catch (Exception ex)
{
Logger.Log("Android crash", ex, nameof(Wallet.Droid));
Toast.MakeText(ApplicationContext, ex.ToString(), ToastLength.Long).Show();
}
}
private async Task<string> GetPin()
{
var taskCompletionSource = new TaskCompletionSource<string>();
RunOnUiThread(async () =>
{
var pin = await TrezorPinPad.GetPin();
taskCompletionSource.SetResult(pin);
});
return await taskCompletionSource.Task;
}
protected override void OnResume()
{
base.OnResume();
Logger.Log($"Resuming... Setting up Trezor listeners. _TrezorHidDevice is {(_TrezorHidDevice == null ? "null" : "not null")}", null, nameof(Wallet.Droid));
RegisterReceiver();
}
private void RegisterReceiver()
{
try
{
lock (_ReceiverLock)
{
if (_UsbDeviceAttachedReceiver != null)
{
UnregisterReceiver(_UsbDeviceAttachedReceiver);
_UsbDeviceAttachedReceiver.Dispose();
}
_UsbDeviceAttachedReceiver = new UsbDeviceAttachedReceiver(_TrezorHidDevice);
RegisterReceiver(_UsbDeviceAttachedReceiver, new IntentFilter(UsbManager.ActionUsbDeviceAttached));
if (_UsbDeviceDetachedReceiver != null)
{
UnregisterReceiver(_UsbDeviceDetachedReceiver);
_UsbDeviceDetachedReceiver.Dispose();
}
_UsbDeviceDetachedReceiver = new UsbDeviceDetachedReceiver(_TrezorHidDevice);
RegisterReceiver(_UsbDeviceDetachedReceiver, new IntentFilter(UsbManager.ActionUsbDeviceDetached));
}
}
catch (Exception ex)
{
Logger.Log($"Error registering Hid receivers", ex, nameof(Wallet.Droid));
}
}
#endregion
}
If you start your application, from within another application/or using the ClearTask flag/or if your app is performing a cold start (has been closed in the background), and perhaps i other ways as well, you will see a "Preview" screen, which is the background of your current theme (kind of what you are already doing for your SplashScreen, which shows the theme background)...
But if your "#style/MainTheme" has a simple white background, this will be what you might see when reentering your app.
Therefore you can consider using the "SetTheme" method in OnCreate. There is more about this in this link:
https://developer.android.com/topic/performance/vitals/launch-time
Hope it helps.
Related
I am building an app which uses Camera2API to take pictures. The thing is I need the Camera to take a picture without needing a preview. So far, I managed to do it by dumping (and adapting) the code from an activity into a service and it works like a charm, except for the fact that it is not focusing. On previous versions I had a state machine in charge of that focusing on the preview by means of a separate CaptureRequest.Builder, but I can't make it work without creating a new CaptureRequest.Builder on the service.
I followed this topic on the following stackoverflow discussion How to lock focus in camera2 api, android? but I did not manage to make it work.
My code does the following:
First I create a camera session once the camera has been opened.
public void createCameraSession() {
try {
// Here, we create a CameraCaptureSession for camera preview.
cameraDevice.createCaptureSession(Arrays.asList(imageReader.getSurface()),
new CameraCaptureSession.StateCallback() {
#Override
public void onConfigured(#NonNull CameraCaptureSession cameraCaptureSession) {
// The camera is already closed
if (null == cameraDevice) {
return;
}
// When the session is ready, we start displaying the preview.
mCaptureSession = cameraCaptureSession;
camera2TakePicture();
}
#Override
public void onConfigureFailed(
#NonNull CameraCaptureSession cameraCaptureSession) {
}
}, null
);
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
Then on that camera session I call my method "camera2TakePicture()":
protected void camera2TakePicture() {
if (null == cameraDevice) {
return;
}
try {
Surface readerSurface = imageReader.getSurface();
List<Surface> outputSurfaces = new ArrayList<Surface>(2);
outputSurfaces.add(readerSurface);
final CaptureRequest.Builder captureBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
captureBuilder.addTarget(readerSurface);
captureBuilder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO);
captureBuilder.set(CaptureRequest.CONTROL_AF_MODE, CameraMetadata.CONTROL_AF_MODE_AUTO);
captureBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_START);
//MeteringRectangle meteringRectangle = getAFRegion();
//captureBuilder.set(CaptureRequest.CONTROL_AF_REGIONS, new MeteringRectangle[] {meteringRectangle});
/**** TO BE USED ONCE SAMSUNG TABLETS HAVE BEEN REPLACED ****/
boolean samsungReplaced = false;
if(Boolean.parseBoolean(getPreferenceValue(this, "manualCamSettings"))) {
int exposureCompensation = Integer.parseInt(getPreferenceValue(this, "exposureCompensation"));
captureBuilder.set(CaptureRequest.CONTROL_AE_EXPOSURE_COMPENSATION, exposureCompensation);
if(samsungReplaced) {
//Exposure
captureBuilder.set(CaptureRequest.CONTROL_AE_MODE, CameraMetadata.CONTROL_AE_MODE_OFF);
Float shutterSpeed = 1 / Float.parseFloat(getPreferenceValue(this, "camSSpeed"));
Long exposureTimeInNanoSec = new Long(Math.round(shutterSpeed * Math.pow(10, 9)));
captureBuilder.set(CaptureRequest.SENSOR_EXPOSURE_TIME, exposureTimeInNanoSec);
captureBuilder.set(CaptureRequest.SENSOR_FRAME_DURATION, 10 * exposureTimeInNanoSec);
//ISO
int ISO = Integer.parseInt(getPreferenceValue(this, "camISO"));
captureBuilder.set(CaptureRequest.SENSOR_SENSITIVITY, ISO);
//Aperture
Float aperture = Float.parseFloat(getPreferenceValue(this, "camAperture"));
captureBuilder.set(CaptureRequest.LENS_APERTURE, aperture);
}
}
// Orientation
WindowManager window = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
Display display = window.getDefaultDisplay();
int rotation = display.getRotation();
captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, ORIENTATIONS.get(rotation));
CameraCaptureSession.CaptureCallback CaptureCallback
= new CameraCaptureSession.CaptureCallback() {
#Override
public void onCaptureCompleted(#NonNull CameraCaptureSession session,
#NonNull CaptureRequest request,
#NonNull TotalCaptureResult result) {
super.onCaptureCompleted(session, request, result);
while(result.get(CaptureResult.CONTROL_AF_STATE) != CaptureResult.CONTROL_AF_STATE_FOCUSED_LOCKED){
System.out.println("Not focused");
}
System.out.println("Focused");
}
};
mCaptureSession.stopRepeating();
mCaptureSession.abortCaptures();
mCaptureSession.capture(captureBuilder.build(), CaptureCallback, null);
captureBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_IDLE);
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
As you can see, I set the CONTROL_AF_MODE to AUTO then start the AF_TRIGGER and launch the capture. I add a check on onCaptureCompleted() but the AF_STATE never seems to be on FOCUSED_LOCKED. It stays on ACTIVE_SCAN.
What am I doing wrong?
In your code snippet, you've stopped the repeating request, and issue one capture request for the still image, but just one.
Do you then go on to restart the repeating request? If you don't, there are no frames flowing through the camera, and AF cannot make progress.
So if you want to lock AF before you take a picture, you want to
Set AF_TRIGGER to START for a single capture only
Run preview until you get AE_STATE out of ACTIVE_SCAN
Issue single capture for still image.
Being in the background or foreground doesn't really change any of this.
I want to add a listener to the local notification so when the user press on the notification a browser opens, this is my code :
public class MyApplication {
private Form current;
private Resources theme;
Form hi;
Form web;
EncodedImage ei;
Image img;
String url = "https://d1fmx1rbmqrxrr.cloudfront.net/cnet/optim/i/edit/2019/04/eso1644bsmall__w770.jpg";
public void init(Object context) {
// use two network threads instead of one
updateNetworkThreadCount(2);
theme = UIManager.initFirstTheme("/theme");
// Enable Toolbar on all Forms by default
Toolbar.setGlobalToolbar(true);
// Pro only feature
Log.bindCrashProtection(true);
addNetworkErrorListener(err -> {
// prevent the event from propagating
err.consume();
if (err.getError() != null) {
Log.e(err.getError());
}
Log.sendLogAsync();
Dialog.show("Connection Error", "There was a networking error in the connection to " + err.getConnectionRequest().getUrl(), "OK", null);
});
}
public void start() {
if (current != null) {
current.show();
return;
}
try {
ei = EncodedImage.create("/loading.gif");
} catch (IOException ex) {
System.out.println(ex.getMessage());
}
img = URLImage.createToStorage(ei, url, url, URLImage.RESIZE_SCALE);
LocalNotification n = new LocalNotification();
n.setId("Welcome");
n.setAlertBody("Welcome");
n.setAlertTitle("Welcome");
// n.setAlertSound("/notification_sound_bells.mp3"); //file name must begin with notification_sound
n.setAlertImage(img.toString());
n.setId("5");
n.setBadgeNumber(0);
Display.getInstance().scheduleLocalNotification(
n,
System.currentTimeMillis() + 10 * 1000, // fire date/time
LocalNotification.REPEAT_NONE // Whether to repeat and what frequency
);
if (n.getBadgeNumber() > 0) {
localNotificationReceived("5");
}
hi = new Form("Hi World", BoxLayout.y());
web = new Form("web", BoxLayout.y());
hi.add(new Label("Hi World"));
BrowserComponent browser = new BrowserComponent();
browser.setURL("https://www.codenameone.com/");
web.add(browser);
hi.show();
}
public void localNotificationReceived(String notificationId) {
web.show();
}
public void stop() {
current = getCurrentForm();
if (current instanceof Dialog) {
((Dialog) current).dispose();
current = getCurrentForm();
}
}
public void destroy() {
}
}
but no action was executed on the moment of the press.
Another problem the image passed in the notification didn't appear.
I tried to see the official documentation but nothing useful found.
You're relying on APIs such as badging which aren't supported everywhere. You should remove that code. The reason notifications aren't invoked is that you didn't implement the LocalNotificationCallback interface in your main class. You just wrote the method without implementing the interface.
I am having an issue calling background function which is written for android specific. My use case - press on the button, schedule the SMS (with alarm manager), call callback function, and send SMS.
I'm feeling stuck a bit so I hope someone can show me what can I do to make it right.
Also if I put await platform.invokeMethod('sendsms') on button press, the method fires. So I am doing something wrong when trying to fire the method in the backend.
Here is also a gist with all files: https://gist.github.com/benzo11/901c1885fff46e37d954a139dbbf0470
Thank you in advance!
// In the widget state class
Future<void> _sendSms() async {
await AndroidAlarmManager.oneShotAt(
DateTime.now().add(const Duration(seconds: 1)),
1,
printHello, // callback function which triggers
alarmClock: true,
);
}
// Top level
void printHello() async {
final DateTime now = DateTime.now();
final int isolateId = Isolate.current.hashCode;
print("[$now] Hello, world! isolate=${isolateId} function='$printHello'");
// Method undefined in isolate
var result = await platform.invokeMethod('sendsms').then((res) {
print(res);
});
}
public class MainActivity extends FlutterActivity {
public static final String TAG = "AlarmExampleMainActivity";
private static final String CHANNEL = "samples.flutter.dev/battery";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidAlarmManagerPlugin
.registerWith(registrarFor("io.flutter.plugins.androidalarmmanager.AndroidAlarmManagerPlugin"));
}
#Override
public void configureFlutterEngine(#NonNull FlutterEngine flutterEngine) {
super.configureFlutterEngine(flutterEngine);
new MethodChannel(flutterEngine.getDartExecutor().getBinaryMessenger(), CHANNEL)
.setMethodCallHandler((call, result) -> {
// Note: this method is invoked on the main thread.
if (call.method.equals("sendsms")) {
String rez = sendSMS();
result.success(rez);
} else {
result.notImplemented();
}
});
}
private String sendSMS() {
String phoneNo = "009981111";
String msg = "Message body";
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNo, null, msg, null, null);
return "Sent";
}
}
I'm currently working on a android app in which I use asynctasks to carry out json rest request. I've got this working fine. I have also got a progress dialog being made visible on the preexecute then dismissing it on the postexecute all working fine. see code below.
#Override
protected void onPreExecute(){
Variables var = Variables.getInstance();
Variables.getInstance().showPd(ProgressDialog.show(Variables.getInstance().getContext(), var.getValue("loggingin_text"), var.getValue("pleasewait"), true, false));
}
protected void onPostExecute( JSONObject[] loginresponse ){
Variables.getInstance().dismisspd();
try {
JSONObject responseheader = loginresponse[0].getJSONObject("commonInputParameters");
if (responseheader.getString("status").equals("SUCCESS")) {
Variables.getInstance().setUsername( loginresponse[1].getString("username") );
Variables.getInstance().setSessiontoken(responseheader.getString("userSessionToken"));
delegate.onRequestCompletion( true );
} else {
delegate.onRequestCompletion(false);
}
}catch (JSONException je ) {
this.cancel( true );
}
}
final Button _loginBTN = ( Button ) findViewById(R.id.loginBTN );
_loginBTN.setText( vars.getValue( "loginbtn_text" ) );
_loginBTN.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final Functions functions = Functions.getInstance();
if( functions.isNetworkAvailable(getApplicationContext())) {
if (functions.fullypopulated(new Object[]{_username, _password})) {
LoginRequest login = new LoginRequest(new responseInterface() {
#Override
public void onRequestCompletion(boolean successfulRequest) {
Variables.getInstance().dismisspd();
if ( !successfulRequest ) {
functions.showDialog(Variables.getInstance().getValue("login_err"), findViewById(R.id.input_username));
functions.clearEditText(new EditText[]{_username, _password});
functions.setError(new EditText[]{_username, _password});
} else {
Intent intent = new Intent(getApplicationContext(), NavigationHandler.class);
startActivity(intent);
finish();
}
}
#Override
public void onRequestCompletion(String requestResponse) {}
#Override
public void onRequestCompletion(int requestResponse) {}
#Override
public void onRequestCompletion(float requestResponse) {}
});
Map<String, String> loginDetails = new HashMap<String, String>();
loginDetails.put("username", _username.getText().toString());
loginDetails.put("password", _password.getText().toString());
login.execute(loginDetails);
} else {
functions.showDialog(Variables.getInstance().getValue("no_details"), findViewById(R.id.input_username));
functions.clearEditText(new EditText[]{_username, _password});
functions.setError(new EditText[]{_username, _password});
}
}
else {
functions.showDialog(Variables.getInstance().getValue("no_network"), findViewById(R.id.input_username));
}
}
});
The problem is that when I try to work in a time out into the async task the progress dialog shows but not until after it has completed and at which point I can't remove it.
This is how I'm trying to run it with a time out.
try{
login.execute(loginDetails).get( 5000, TimeUnit.MILLISECONDS );
}catch (InterruptedException ie ){
}catch (ExecutionException ee){
}catch (TimeoutException te ){
login.cancel(true);
}
Yes I know the catches are empty right now.
UPDATE:
Never mind looking at the get function again, it actually blocks the UI thread that is why the Progress Dialog isn't showing until the ASyncTask has completed. Is there anyway to implement a timeout feature?
Cancelling a task
A task can be cancelled at any time by invoking cancel(boolean). Invoking this method will cause subsequent calls to isCancelled() to return true. After invoking this method, onCancelled(Object), instead of onPostExecute(Object) will be invoked after doInBackground(Object[]) returns.
From http://developer.android.com/reference/android/os/AsyncTask.html
Mind the bold pieces ... as to my understanding, you should dismiss the Dialog in onCancelled() in case of Timeout.
The question is how to communicate with an Android phone to a server, so that if the Activity is left and the call in the Activity was not successful to repeat the transaction once again automatically. Just now I use the AsyncTask of Android to communicate with the server:
new AsyncTask<String, Void, List<String>>() {
#Override
protected void onPreExecute(
showWaitDialog();
}
#Override
protected void onPostExecute(List<String> msgList) {
//here I put the handling after the POST ie. error and success handling
hideWaitDialog();
if (msgList.isEmpty() {
//success handling --> starting an new Activity
} else {
errorView.setText (...);
errorLayout.setVisibility (View.VISIBLE);
}
}
#Override
protected List<String> doInBackground(String... params) {
List<String> msgs = new ArrayList<String>();
try{
//for example submitting an JSONObject
JSONObject result = HttpUtils.sendHttpPost(
AppConstants.WEB_URL, jsonObject);
//error handling on the result
boolean hasErrors = JsonResult.isOk(result);
if (hasErrors) {
// adding errors to msgs list
String[] errorMessages = JsonResult.getErrorMessages (result,...);
fillList (msgs, errorMessages);
return msgs;
}
} catch (CommunicationError er) {
msgs.add (er...);
}
return msgs;
}
}
The problem with this approach is, that if I don't have a successful transmission of the data I must stay in the same Activity. Until now I show an error message to the user and he is in charge to submit by a button again the results to the server.
What I'm looking for is some Activity that remains persistent in the memory which runs later in the case that the transmission wasn't made.
As an application case I use this to dynamically upload pictures for a Waypoint in a map if I pressed that waypoint. In some case it can happens that the connection to the mobile service provider isn't available (mountains, forest, far apart from antenna). Then I want to leave the map Activity and switch to the detail view of this waypoint. In the success case I put the picture into my model classes and make an serialization. If the user clicks again on the same waypoint the picture is not loaded again. In the non success case I don't want to wait that the user clicks against on the waypoint to retrieve the image. In fact I need a background task, some sort of a queue that pictures of waypoints that are already visited on couldn't be retrieved are loaded until the communication part gives back a positive result and the image can be written into the model. The next time the user is pressing the Waypoint the picture will be then present.
Are there any best practices for making such a code implementation?
Is there any example around?
Is there a better way of doing this?
Yes, you need to Implement Intent Service for this requirement
According to the developers website
The IntentService class provides a straightforward structure for running an operation on a single background thread.
For complete details and working source code, Go through the Android Docs
Thanks to the answer of David.
I just read after the suggestion the tutorial at
[1] http://code.tutsplus.com/tutorials/android-fundamentals-intentservice-basics--mobile-6183
After my tests I prefered a Service (not an IntentService)
and created a service: SubmissionService
public class SubmissionIntentService extends Service {
private List<PendingMessage> pMsgList = new CopyOnWriteArrayList<PendingMessage>();
private Handler handler = new Handler();
private boolean hasAppStopped = false;
private Runnable runner;
public SubmissionIntentService() {
super();
Log.d (TAG, "Service created...");
}
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
PendingMessage pMessage = (PendingMessage) intent.getParcelableExtra(AppConstants.MESSAGE_OBJECT);
synchronized (pMsgList) {
pMsgList.add(pMessage);
}
if (runner == null) {
handler.postDelayed(runner = initializeRunnable(), 500);
}
return Service.START_NOT_STICKY;
}
private void runAsLongAppIsActive (Runnable runner) {
if (!hasAppStopped) {
handler.postDelayed (runner, SOME_INTERVAL_CONSTANT);
}
}
private Runnable initializeRunnable() {
Runnable result;
result = new Runnable() {
#Override
public void run() {
if (pMsgList.isEmpty()) {
runAsLongAppIsActive (this);
return;
}
PendingMessage[] pMArray = null;
synchronized(pMsgList) {
pMArray = pMsgList.toArray (new PendingMessage[pMsgList.size()]);
}
if (pMArray==null || pMArray.length==0) {
runAsLongAppIsActive (this);
return;
}
Log.d (TAG, "Message List size is actually :"+pMArray.length);
for (PendingMessage pM: pMArray) {
try {
JSONObject jsonMess = JSONSendMessage.buildOutput (pM);
JSONObject result = HttupUtils.sendHttpPost (WEB_URL, jsonMess);
boolean hasErrors = JSONResult.isOk (result);
if (hasErrors) {
//TODO: error handling in case of transmission
//don't remove the message from the queue
runAsLongAppIsActive(this);
return;
}
//remove pending transmission of the queue if success
synchronized (pMsgList) {
pMsgList.remove (pM);
}
//inform over receiver if activity is shown
Intent broadcastIntent = new Intent();
//put data in intent
sendBroadcast (intent);
//more important
WayPointModel model = ModelInstance.getWayPointModel();
model.addToModel (pM, result);
model.store();
} catch (Exception e) {
continue; //try to send other messages
}
}
runAsLongAppIsActive (this);
}
};
return result;
}
}
#Override
public void onDestroy() {
hasAppStopped = true;
handler.removeCallbacks (runner);
super.onDestroy();
}
}
Further I added a ResponseReceiver:
public class ResponseReceiver extends BroadcastReceiver {
public static final String ACTION_RESP = "MESSAGE_PROCESSED";
#Override
public void onReceive(Context context, Intent intent) {
//work in progress...
}
}
and in the Activity where I want to be informed about events:
public class SomeActivity extends Activity {
private ResponseReceiver receiver;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
IntentFilter filter = new IntentFilter(ResponseReceiver.ACTION_RESP);
filter.addCategory(Intent.CATEGORY_DEFAULT);
receiver = new ResponseReceiver();
registerReceiver(receiver, filter);
...
}
}
and finally to send messages over Http:
Intent msgIntent = new Intent(this, SubmissionIntentService.class);
msgIntent.putExtra(...);
startService(msgIntent);
don't forget to declare the service in your manifest:
<service android:name="ch.xxx.app.service.SubmissionIntentService" />
Observations:
- I called the method startService(...) from different Activities. The constructor is only called once.
==> I have just on instance of the service for all Activities (exactly what I need).
What I don't get until now:
- Putting back data to the Activity. What is if the Activity is at the moment no shown?