Why can't I kill an Activity I started using killBackgroundProcesses? - android

OK, I'm stumped :-(
As an experiment, I've been trying to start an Activity and then sometime later shut it down using killBackgroundProcesses from the ActivityManager package. I'm not getting any errors. It just doesn't seem to do anything.
The code below is narrowed down about as much as I can get it. Just as a test, I start the Activity (successfully) and then when my onPause method gets called, I try and and stop what I had just started (in my real code, this happens much later).
Typing this up, it occurred to me that perhaps using killBackgroundProcesses on an Activity that is currently on-screen may not be meaningful. If so, is there any other way to stop this Activity? I do not have source to this other app, I started it up, and now I just want it to go away. And I also realize that this is not a normal Activity lifecycle behavior, but at least for now, this is a special case for me.
I'd appreciate any insight or solutions.
Thanks!
Manifest:
...
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES"/>
...
Code:
public class MainActivity extends Activity
{
static String PACKAGE = "com.abc.def";
...
Intent i = getPackageManager().getLaunchIntentForPackage( PACKAGE );
startActivity( i );
...
#Override
protected void onPause()
{
// just to see if we can, kill the activity we just started
ActivityManager manager = (ActivityManager)getApplicationContext().getSystemService( Context.ACTIVITY_SERVICE );
manager.killBackgroundProcesses( PACKAGE );
}
}

Calling killBackgroundProcesses is allowed for Android framework (internal system or partner rom developers like HTC, Samsung, etc) only and not the third-party applications. Instead, you should call finish(); on your activity's onPause or onStop method to destroy it automatically when its gone from screen.

Related

Android intent BOOT_COMPLETED is never launched on Samsung SM-T230 Kitkat 4.4.2 tablet

I'm creating a HOME (android.intent.category.HOME) typed application which launchs another app as soon as the first one is launched. Up until now I've been using onResume() on the activity fragment, which was working great (meaning on other tablets with other Android version) until I tried it on an SM-T230 (Galaxy Tab 4 7" Wifi) which has Kitkat 4.4.2.
I don't know why but with that tablet the "BOOT_COMPLETED" intent is never fired. I've tried launching many different apps and with every single one of them happens the same thing. The aforementioned intent is never launched. Only after pressing back repeatedly and getting back to the HOME typed app it is launched (it must be done repeatedly since the app launches every time in onResume() the second app). If it is never launched by the system, the wifi service, tethering and many more will not function.
Interestingly if I omit the launch of the second app, the intent is fired.
I'm thinking on trying to launch the app as soon as the HOME app fragment becomes visible but I have no idea as of how to do it. Does someone has any idea on how to do that?
Also if you have encountered the same problem I would like to read your comments.
The problem was that the second app was launched before the first android fragment is visible. To solve this problem I added a very small timer that launches the second app after it times out.
#Override
public void onResume() {
super.onResume();
...
getView().postDelayed(scheduleLaunch, 2000);
}
private Runnable scheduleLaunch = new Runnable() {
#Override
public void run() {
if (isAdded()) {
launchMainApp();
}
}
};
Did you add permission?
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

Google Espresso java.lang.RuntimeException: Could not launch intent Intent { act=android.intent.action.MAIN

I am new to Espresso UI testing.
I am getting this error while running tests (ADT Eclipse IDE ).
The app is already developed and there are lots of request going on while launching the app. it is not possible to rewrite the app. but i need to find the way to test this UI even if there is any delay in the loading of the components.
java.lang.RuntimeException: Could not launch intent Intent { act=android.intent.action.MAIN flg=0x14000000 cmp=com.xx.android/com.yy.core.android.map.MapActivity } within 45 seconds. Perhaps the main thread has not gone idle within a reasonable amount of time? There could be an animation or something constantly repainting the screen. Or the activity is doing network calls on creation? See the threaddump logs. For your reference the last time the event queue was idle before your activity launch request was 1390913271702 and and now the last time the queue went idle was: 1390913271767. If these numbers are the same your activity might be hogging the event queue.
at com.google.android.apps.common.testing.testrunner.GoogleInstrumentation.startActivitySync(GoogleInstrumentation.java:277)
at android.test.InstrumentationTestCase.launchActivityWithIntent(InstrumentationTestCase.java:119)
at android.test.InstrumentationTestCase.launchActivity(InstrumentationTestCase.java:97)
at android.test.ActivityInstrumentationTestCase2.getActivity(ActivityInstrumentationTestCase2.java:104)
at com.gulesider.android.test.UItest.setUp(UItest.java:25)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:190)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:175)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:555)
at com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner.onStart(GoogleInstrumentationTestRunner.java:167)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1799)
I have one library project called “Core” - it will not generate any .apk
Also i have one Android project called “AA” which will access “Core”. - This is AA.apk
Now i have created a test project called “UItest”
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.AA.android.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8"
android:targetSdkVersion="18" />
<instrumentation
android:name="com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"
android:targetPackage="com.AA.android"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name="com.core.android.map.MapActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<uses-library android:name="android.test.runner" />
</application>
</manifest>
My test:
public class UItest extends ActivityInstrumentationTestCase2<MapActivity> {
public UItest() {
super(MapActivity.class);
}
#Override
public void setUp() throws Exception {
super.setUp();
getActivity();
}
public void testSearchBox() {
Espresso.onView(ViewMatchers.withId(R.id.menu_button_logo)).perform(ViewActions.click());
}
}
For Espresso Testing it is highly recommend that you turn off system animations on the virtual or physical device(s) used for testing. So you can follow the steps below to manually turn off the animations:
Under:
Settings->
Developer options->
Drawing
Window Animations scale to OFF
Transition animation scale to OFF
Animator duration scale to OFF
If there is a progress bar running when you create the activity, you get an error like this. You should cause a stop for the progress bar in order to continue running the test.
I experienced this error while running Espresso tests on 6.0 devices but not on 5.1.1 or 7.0 devices. I tracked the cause down to using android:fadeScrollbars within a style. Removing this item from my style resolved the issue.
I have stuck into this problem for several hours. Finally, I got the reason.
This works for me.
Here are some different reasons, according to the phenomenon.
Activity can't be launched
Activity launched, but UI perform actions not work
The first scenario: activity can't be launched
Because of your target Activity maybe already in the activity stack.
Add a CLEAR flag and NEW_TASK flag
#get:Rule
val activityRule = ActivityTestRule<MainActivity>(MainActivity::class.java)
private lateinit var launchedActivity: MainActivity
#Before
fun setUp() {
val intent = Intent(Intent.ACTION_PICK)
//this is the key part
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
//this is the key part
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
launchedActivity = activityRule.launchActivity(intent)
}
The second scenario: activity launched but UI perform actions not work
In this scenario may be because of
Your code is executing some animation in a long time
Your code is doing a UI logic that you don't notice
(like Handler post event or runnable)
(register a listener in ViewTreeObserver like OnPreDrawListener and didn't unregister in a proper timing)
These actions may lead to UI thread busy, so the espresso can not do the test.
Probably you have animation inside your activity, which blocks espresso execution. You have to disable it - see https://github.com/googlesamples/android-testing/tree/master/ui/espresso/BasicSample
In my case a custom view caused this behaviour. It contained a Scroller which was constantly scrolling. Unfortunately, I didn't find a solution for this issue until now except disabling it for the tests...
If you are performing this test in MI or XIOMI phone then maybe it will not work so you can change device or you can use bluestack emulator. It will be work
At the very first page you will be calling too many request which will be taking time more than 15 seconds, the first page should be very lightwieght.
Just try by creating one new welcome page and then calling your original welcome page.
Hope this work for you.
Well, in my case it was caused by a strange thing.
One of my UI tests opened the external intent "android.app.action.CONFIRM_DEVICE_CREDENTIAL" so I decided to stub it. From now on, the MAIN intent didnt launch again until I manually closed the screen oipened by "android.app.action.CONFIRM_DEVICE_CREDENTIAL" from the recent tasks.
No idea why this happened, and have no time now for research. Maybe later I will update this thread.
I faced this error when I trying to test the opening of another activity when the user clicked on a given view. What I was doing wrong was not replacing:
#Rule
public ActivityTestRule<MyActivity> myActivityActivityTestRule = new ActivityTestRule<>(MyActivity.class);
Per:
#Rule
public IntentsTestRule<MyActivity> myActivityActivityTestRule =
new IntentsTestRule<>(MyActivity.class);
I had this problem too, and in the moment I changed physical device to other Android phone the tests were working. Just try to use other device. And use #rule for launching activity

Android Application onCreate not called for homescreen launcher app during reboot

I am having a strange problem in an Android application that I am building, the application is basically a Homescreen replacement app which will be put as a default homescreen in a device. To do some initialization work I have extended Android Application class and in the onCreate() method I am basically registering some observer and starting a service, here's the code:
public class MyApplication extends Application implements ExternalStorageListener {
private ExternalStorageObserver externalStorageObserver;
public void onCreate() {
Log.i("MyApplication", "Starting application");
super.onCreate();
externalStorageObserver = new ExternalStorageObserver(this);
if(externalStorageObserver.isExternalStorageAvailable()) {
// this builds a list of files present in the SD card
// which is being used through the application to do
// some work
buildData();
File externalFileDir = getApplicationContext().getExternalFilesDir(null);
if(externalFileDir != null && externalFileDir.isDirectory()) {
// do something...
}
}
//Register listener to observe external storage state
registerExternalStorageObserver();
Log.i("SyncService", "Starting sync service...");
ComponentName cmp = startService(new Intent(getApplicationContext(), SyncService.class));
Log.i("SyncService", cmp.toString());
}
private void registerExternalStorageObserver() {
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_MEDIA_MOUNTED);
filter.addAction(Intent.ACTION_MEDIA_REMOVED);
registerReceiver(externalStorageObserver, filter);
}
private void buildData() {
// builds a list
}
}
Content of Manifest file:
<application android:persistent="true" android:icon="#drawable/icon"
android:label="#string/app_name" android:name="com.webgyani.android.MyApplication"
android:debuggable="true">
<activity android:name=".HomeTabActivity" android:launchMode="singleInstance"
android:stateNotNeeded="true" android:theme="#style/LightTabsTheme"
android:screenOrientation="landscape" android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
This works fine when I install the app either using Eclipse or manually installing the apk onto the device. Once the app is installed things work fine, I mean the above onCreate() method gets called and service is also started normally, but if I reboot the device this time the onCreate() method does not get called(none of the log statements appear and also the services are not started). After some debugging I noticed that this only happens if I set my app as the default launcher/homescreen app and thereafter reboots the device, because once you set the app as the default launcher, Android should automatically launch your app as the homescreen after reboot. In my case the app is launched but that code is not executed.
I tried to use debugger but that didn't work because when I reboot the device the debugger gets disconnected and by the time USB debugging gets enabled my app is already started.
I even double checked the Logcat but didn't see any error. I thought of having a BOOT_COMPLETED intent to initialize that part, but that will require some code refactoring which I am not willing to do at this point of time unless there is a solution.
So I am curious to know that whether this is a standard behavior, or is there a known bug which causes this, because my assumption is the onCreate method of the Application will always get called whenever the app is started. I have tried whatever I could since morning, but nothing worked, couldn't pinpoint the issue, if any of you could shed some light into this then that would be highly appreciated.
Thanks
Well, finally I figured out the problem, and it was in my code itself. I initially suspected that the MyApplication's onCreate() method was not getting called, I had that assumption because I was not able to see any logs. To know whether the method is getting called or not, instead of using Log.i() I was also appending some additional log messages in an ArrayList and printing them later, this revealed that the methods were indeed getting called and even the Service was instantiating properly but the data or filelist is not being populated because the SDCard was not ready by that time. I am also pretty sure that the logs were not available on Logcat due to the fact that the USB debugger becomes ready after my app is started(as it's a homescreen app).
The actual problem becomes obvious when you see that my overridden MyApplication class implements a listener called ExternalStorageListener which basically extends BroadcastReceiver, I have created that class to receive SDCard related Intents for example ACTION_MEDIA_MOUNTED, ACTION_MEDIA_REMOVED to rebuild the data(file list). In my case the ExternalStorageListener class was not receiving the Intents because I forgot to add this filter.addDataScheme("file") in the registerExternalStorageObserver method above in the code sample.
I do agree that my question was based on a false assumption and the code example I posted it's kind of hard to figure out the actual issue. I am not sure what to do with the question whether to mark this as answer or leave it as it is.

Android launches system settings instead of my app

For some reason whenever I (try to) start my app the phone decides to launch system settings instead of my "main activity". And yes, I am referring to the "Android system settings", and not something from my app.
This only happens on my phone, and I suppose it probably could be related to the fact that my app had just opened system settings when I decided to re-launch with a new version from Eclipse.
It is possible to start the app from within Eclipse, but when I navigate back from the app it returns to the system settings rather than the home screen, as if the settings activity was started first and then my activity. If I then start the app from the phone all I get is system settings yet again.
The app is listening to the VIEW-action for a specific URL substring, and when I start the app using a matching URL I get the same result as when I start it from Eclipse, app starts, but when I return I return to settings.
I have tried googling for this problem, and all I could find was something about Android saving state when an app gets killed, but without any information on how to reset this state. I have tried uninstalling the app, killing system settings, rebooting the phone, reinstalling, clearing application data.. no luck..
For what it's worth, here's the definition of my main activity from the manifest,
<activity android:name=".HomeActivity" android:label="#string/app_name" android:screenOrientation="portrait" android:clearTaskOnLaunch="true" android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"></action>
<category android:name="android.intent.category.DEFAULT"></category>
<category android:name="android.intent.category.BROWSABLE"></category>
<data android:pathPrefix="/isak-web-mobile/smart/" android:scheme="http" android:host="*"></data>
</intent-filter>
</activity>
And here is the logcat-line from when I try to start my app, nothing about any settings anywhere.
I/ActivityManager( 1301): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=se.opencare.isak/.HomeActivity }
When I launch from Eclipse I also get this line (as one would expect),
I/ActivityManager( 1301): Start proc se.opencare.isak for activity se.opencare.isak/.HomeActivity: pid=23068 uid=10163 gids={3003, 1007, 1015}
If it matters the phone is a HTC Desire Z running 2.2.1.
Currently, this is my HomeActivity,
public class HomeActivity extends Activity {
public static final String TAG = "HomeActivity";
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d(TAG, "onActivityResult(" + requestCode + ", " + resultCode + ", " + data + ")");
super.onActivityResult(requestCode, resultCode, data);
}
#Override
protected void onCreate(Bundle savedInstanceState) {
Log.d(TAG, "onCreate(" + savedInstanceState + ")");
super.onCreate(savedInstanceState);
}
#Override
protected void onDestroy() {
Log.d(TAG, "onDestroy()");
super.onDestroy();
}
#Override
protected void onPause() {
Log.d(TAG, "onPause()");
super.onPause();
}
#Override
protected void onPostCreate(Bundle savedInstanceState) {
Log.d(TAG, "onPostCreate(" + savedInstanceState + ")");
super.onPostCreate(savedInstanceState);
}
#Override
protected void onPostResume() {
Log.d(TAG, "onPostResume()");
super.onPostResume();
}
#Override
protected void onRestart() {
Log.d(TAG, "onRestart()");
super.onRestart();
}
#Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
Log.d(TAG, "onRestoreInstanceState(" + savedInstanceState + ")");
super.onRestoreInstanceState(savedInstanceState);
}
#Override
protected void onResume() {
Log.d(TAG, "onResume()");
super.onResume();
}
#Override
protected void onStart() {
Log.d(TAG, "onStart()");
super.onStart();
}
#Override
protected void onStop() {
Log.d(TAG, "onStop()");
super.onStop();
}
#Override
protected void onUserLeaveHint() {
Log.d(TAG, "onUserLeaveHint()");
super.onUserLeaveHint();
}
}
Nothing (of the above) is written to the log.
After reading Blundell's response I have tried changing the launchMode/clearTaskOnLaunch settings, with the following results,
Situation A - I remove launchMode and clearTaskOnLaunch: same problem as before
Situation B - I remove clearTaskOnLaunch and keeps launchMode="singleInstance": another problem
Open app - My HomeActivity is showing
Click on a button to open another activity within my app - it opens as it should
Click on the system back-button - it returns me to system settings
Click on the system back-button again - I am returned to my HomeActivity
Another click on the back-button brings me back to the Android home screen
Situation C - I remove only launchMode and keeps clearTaskOnLaunch: same problem as before
Sitatuion D - I remove clearTaskOnLaunch and set launchMode="singleInstance": same as situation B
You are not calling setContentView() from the HomeActivity (as per the code added by you). And when it is not present, different device behave differently, like on emulator you will see "Application not installed on your phone". Try setting content view.
I've tested this on my phone, but this seems to work correctly here...
What if you try to create a new project, and then just copy the code into it?
It worked for me, maybe it will work for you to...
I suspect it has something to do with your change of version of Eclipse, which might use some different setting from the version you used before, therefore rendering your initial set-up as useless...
My 2Cents
You could look into the launch activity of the Application.
Basically what I think might be happening is, your app is being launched in the same 'Stack' as the settings was, therefore the OS will push the settings to the screen and then load your activity on top of that stack.
You could try adding:
android:launchMode="singleInstance"
into your <activity /> tag of your manifest file. This will start a new stack for your application and only your application
This may fix the issue but there may be another cause and this may cause adverse effects depending on how your app works. Have a look at the documentation for further info:Android:LaunchMode
EDIT
Reading your manifest, why not just remove android:launchMode="singleTop" and let it launch with the default?
Also you are pairing this with:android:clearTaskOnLaunch , because the OS has the settings activity and your activity as the same task it may be clearing it down to the 'root' activity which is the settings and not your app. Is there a reason you have this, remove it and try again?
Please note that I am not an Android developer, but I own an Android phone and think this issue is quite interesting.
To sum it up what I have read about this issue so far here it looks for me that following may be the root cause of this issue:
You use clearTaskOnLaunch, which wipes out all intents/activities/tasks/whatever_buzzword_is_used_for_this when your application starts.
Android then seems to remember permanently the last state of the application in some (what I now will call) global internal state database (GISD for brevity) which cannot be wiped that easily (at least not with uninstalling the application, rebooting, clearing intents, etc.).
Android tries to reopen the application with it's last state. If there is no current activity then this info is taken from the GISD, hence in your case it is "system settings".
There is no way (or it is unknown how) to wipe the state held in the GISD. (Your question is how to do that.)
If this is true this is clearly a phone issue, a major bug in Android, as you then can probably brick applications! All you must do is following:
Somehow provoke a similar thing like clearTaskOnLaunch - which should be possible - for the application you want to brick.
Trick the application to launch to some other application like "System settings" - many applications do this to enable WiFi or similar, but I think some clever people (read: not me) will find a way to do this for virtually any application
Now kill the application in this state.
Android will remember that state then in the GISD and if you try to launch the application from Home screen this will fail in future. Nice.
However even in the absence of a fix hopefully it is possible to bring back the application the same way:
Start your application with an Activity such that it launches. As you write, this works for you.
Apply what clearTaskOnLaunch does. (I really have no idea how, but you as Android developer probably know.)
Let your application launch a third application such that this third application becomes the global state.
Kill your application.
Perhaps timing and sequence is important, so perhaps you have to leave the third application after your application is killed, perhaps you have to pull the battery of your phone at the right time, perhaps you must use some weird ADB stuff to prevent your phone to do the right thing, perhaps you need another sequence of actions or somethign still is missing, whatever, even finding out how to provoke your type of error can be difficult - but thanks to your finding we know there is such a thing.
If you can make Android launch the third application from Home screen instead of your app this would confirm, that you indeed can fix that issue. If this does not work, so it is impossible to prevent Android to invoke system settings instead of your app, then Android certainly has a big problem, as it is likely someone finds a way to permanently brick apps in all those precious phones out there (ab)using that bug.
If the previous step works, however, the last step now is to let this third application launch back into the main screen of your application:
Start your application.
This will launch the third application.
Apply what clearTaskOnLaunch does.
Let the third application launch your application's main screen (or whatever you want)
Kill the third application (and perhaps your application).
Now the global activity state shall be set back to your application again - if everything goes well third application should not be harmed either.
Note that I am not sure this really can be done, as I am not able to test it myself. And having said that all, I agree that we certainly need be a better way to repair this issue!
But interesting would be to see what happens, if your app has the state of the third app and the third app has the state of your app. Does this lead to an endless loop?
Interesting too is, what happens if you deinstall the third app. Does this clean the automatic launch into that application or does it leave you helpless?
As an Android Phone onwer (only), I must say, that's quite a nice mess you have found. And that's why I am highly interested if there is a fix, as doing a factory reset cannot be considered a solution. Read: This is not only a developer problem, it affects Android users as well.
PS: Please forgive me my bad English, the length of this post, not using the right Buzzwords and posting on an issue which I am not an expert of so that my answer is a little bit OT. However I do this with HTH.

Remove from launcher BUT keep enabled / startable

i tried coding it, i tried solving it with google and stackoverflow, nothing found :=) so hopefully someone else has a better idea, im not sure if i get everything right:
i have 2 applications: ad (main app) / adfree-pro (just license starts ad app without ads ;P)
so the problem is, i want to have a pro version (with pro icon) in the launcher, which starts the normal-ad app, which is (the normal ad-app) not in the launcher.
i tried removing the ad-app from the launcher (which due to my research should JUST remove it from the launcher)
pkgMgr.setComponentEnabledSetting(new ComponentName(PACKAGE_NAME, PACKAGE_NAME + ".Main"),
PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
which results to: the icons in the launcher are correct ;) BUT the application can't be found on the phone, launched, started, even not with a launcher pro activity shortcut. it seems to be there (shortcuts can be created) but i crashes with an activity exception when i try to launch it.
02-18 14:38:59.237: ERROR/AndroidRuntime(9941): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {PACKAGE_NAME/PACKAGE_NAME.Main}; have you declared this activity in your AndroidManifest.xml?
which doesnt seem to belong (the error message)
it looks like there has happened more to the application than just simply removed the entry in the launcher.
thanks a lot guys,
every workaround for this situation appreciated :)
best regards :)
You can't have app installed and hide it's launcher icon. The way I'm addressing it with my application which works similar to yours that I don't try to fight icons but instead the app can be launched using ether icon. Obviously you don't have to do in the main (free) app and the code that launches app from your pro icon will look something like the following:
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
// check if main app is installed. If yes then start it
if (appExists()) {
Log.d(TAG, "Started main app from Pro");
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("myapp://com.myapp.main"));
startActivity(intent);
finish();
} else {
// display view with link back to Market
onAppNotExists();
}
}
It's up to you to implement appExists() which is probably some sort of license check
Of course, alternatively you can develop your app's common code as library project and then distribute it in 2 flavors without duplicating the code
BUT the application can't be found on the phone, launched, started,
even not with a launcher pro activity shortcut.
Not application, but activity.
So, if your LAUNCHER activity is BaseActivity, you may create something like BaseFakeActivity (don't forget to set it as LAUNCHER in your manifest instead of your BaseActivity) and which only function is to start your BaseActivity and then finish() itself.
Now you may hide your BaseFakeActivity but you'll still be possible to interact with your BaseActivity.
P.S.: Don't forget to test your app's behaviour after doing things this way ;)

Categories

Resources