Avoid Android APK to run multiple instances - android

In our AndroidManifest.xml, we added android:launchMode="singleInstance" to avoid multiple instances running at the same time.
However, the App now runs in 2 instances at the same time.
This issue only appears when we installed via APK using signed production keystore; when we run in Eclipse, the same issue does not happen at all.
Where else I overlooked ?
p.s. we tried singleTop and singleTask too.
Update: When I click App Icon, it runs. Then, click Home button, it runs again (starts from beginning).

here is your answer. It is long-standing nasty Android bug .This bug happened when your app is launched from other apps (for example, opening from apk installer)
Your problem can be solved by detect when Android has launched a second instance of your root activity into an existing task.
Try this one on your first activity's onCreate:
if(!isTaskRoot()) {
finish();
return;
}

I believe you need to put
<activity
android:launchMode="singleInstance"
/activity>
in the manifest file.

Related

The application sometimes restarts multiple times after shutdown

I have a problem, users report that when the application shuts down (ending the process), the app restarts and user must shuts it down again and the app restarts again. Sometimes even 4x ...
How is it possible? I will close all the services & activities that have been started and I will terminate the whole process ...
I've noticed that only users with android 7 report it to me. It's never happened to me (android 5).
It is the same restart as if the activity is an error, just an exception and a restart. But Fabric.io tool has no record of any errors ... so I do not know what could happen, does anyone have any idea?
Add a Log.d statement into your onCreate in the Application class.
Extent the application class
public class TheApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
Log.d("restart", "My App is restarting");
}
}
and in the manifest
android:name=".TheApplication" <-- make sure the package is correct.
Install the app adb install yourapp.apk
open a terminal
adb logcat restart *:S
then click on your app and watch the terminal.
This way you don't have to run it in debug mode and it runs like a regular app.
If you see it logging the app restarting several times maybe you can put in a trace in places (loging) like put one in the onDestroy of the main launcher class.
hope you figure it out.
It could happen from the 3rd party library that you includes into the project.
Some of them might have a service to trigger something intervally and that wake up the app the couple times.
This issue happened before on the app that i've been working on where the app keep waking up after that particular library get included.
Please check for any service that running in the background.

Android start service of an app from another android app

I have two applications installed on the device: from one app I want to start a service as follows:
Intent i = new Intent();
i.setComponent(new ComponentName("com.app.service", "com.app.service.NotificationService"));
context.startService(i);
The second app is only installed but not started.
What I want is to start the notification service(which should create a notification) from the second service by using the above code.
In the manifest file of the second app I declare the service as follows:
<service
android:name=".service.NotificationService"
android:exported="true" />
The problem is that the Notification Service from the second app does not start.
Any ideas on why this happens?
Just to be clear, the second app is the Notifications one right?
If so, what I would try is loading both apps individually first, and then creating a method in your second one to access the information from the first one.
I had a similar scenario, let me just find the solution (somewhere on my laptop) and get back to you more specifically.
Not exactly a great solution but I have fixed my problem by removing the NotificationService file from the com.app.service directory, and adding it to the com.app directory.
This fixed the issue for me, meaning that I managed to start the service of the second application from the first application.

Why does the new update for my app remove it from the launcher?

I placed a shortcut to my app on the main Android screen, the one you see after unlocking the phone. I then installed my latest update over the top. The app then disappeared from the launcher (but was still in the main list of apps).
I have released many updates where this hasn't happened. However it has happened before, when I replaced our main activity with a new class. That was understandable as maybe the launcher was holding a reference to the class name (rather than the application identifier?).
However this time, that hasn't happened. I have changed the base activity code, and added some new classes to its jar (that then links, and always has linked, with the main eclipse project, rather than be part of it). I've also added some stuff to our manifest:
support-screens now contains android:resizable="true"
have upped the minSdkVersion from 8 to 10
have added a bunch of permissions, including CD2_MESSAGE and WAKE_LOCK
have added a new activity, reciever and service
Any ideas?

Updated app with launcher activity changed causing crash

I have updated my app with change of launcher activity class. User reporting issue about their app icon and shortcut are not working. I want to know is it an OS specific Issue ???
Error they are getting "Linker not available"
Yep, if you have changed the class name for the Activity that used to be an intent launcher, or removed it from being a launcher then peoples current shortcuts won't work.
Simplest answer is to tell them to remove the shortcut and re-add it.
Long solution is to programatically do this yourself (latest Android API's only I believe)
Register the new launcher class in your manifest file.

Android Service application error - no launcher activity

I created a service application without any GUI...infact take help of other applications available on this website...but when i try to run it on my Emulator (2.3.3), I keep on getting error:
2012-02-13 17:36:56 - RUN_SERVICE] No Launcher activity found!
[2012-02-13 17:36:56 - RUN_SERVICE] The launch will only sync the application package on the device!
After it installs properly, but i dont see my service running...i tried adding toast messages, but I am not receving that as well...i didnt try it on real device yet...as I didnt have any phone with this android version 2.3.3. I am using jre6
As your applicatinon does not have any GUI.
You must start the Service from at least one activivity that may be lanucher acitivity by using
<category android:name="android.intent.category.LAUNCHER>
So that your Service need to start when the app is installed or Run.
Make sure you have defined the activity in your AndroidManifest.xml file....
I think you mentioned this in your manifest <category android:name="android.intent.category.LAUNCHER>. if yes then remove this

Categories

Resources