First of all, sorry for the "context" in the question title, I didn't know which word to use. I successfully launch my app by clicking over a URL from another application, but when I launch the task manager I realize that my application is not actually loaded: the caller app holds the activities. I would like how to:
Launch my app in a different "context" (sorry for the word again, which would be better?)
Be able to reload my app in the case it was already loaded (something like restarting it).
Thank you so much.
You can modify the behavior by setting "launchMode" attribute in AndroidManifest.xml to either "singleTask" or "singleInstance", both would cause your Activity to be created as the root of a new task. However it doesn't restart the Activity if it exist already, instead you should handle the Activity.onNewIntent(Intent intent) callback.
To learn more on launchMode see here: http://developer.android.com/guide/topics/manifest/activity-element.html#lmode
In addition to launchMode that Kai mentioned, you might also want to look at taskAffinity and allowTaskReparenting, depending on how your app is structured.
This is an excerpt from there that seems to match how you describe your app:
For example, if an e-mail message contains a link to a web page, clicking the link brings up an activity that can display the page. That activity is defined by the browser application, but is launched as part of the e-mail task. If it's reparented to the browser task, it will be shown when the browser next comes to the front, and will be absent when the e-mail task again comes forward.
Related
I have two separate apps.
The first sends out two different kinds of Broadcasts.
The second one waits for this broadcast from App #1 and uses the broadcast to decide what activity to launch.
What I'm confused about is this: It seems to me that App #2 (the receiving app) shouldn't necessarily require a default activity since the activity it launches depends on the broadcast received from App #1.
But, if a default activity is not defined in App #2, it can't run and throws:
Error running app: Default activity not found
But, if I do define one in the manifest file, then this defeats the purpose of the Broadcast.
Please help me understand the bigger picture and maybe offer a solution.
UPDATE: The issue is solved. To the people facing the same problem, I found 2 possible ways to resolve this:
As suggested by #Lemi Miles, We can simply go to App>edit
Configurations> On launch options and choose Launch "Nothing".
Alternatively, you could create an activity with no functionality to
act as a launcher activity for the app
App>edit Configurations>
On launch options choose Launch "Nothing"
I had this problem since 3 days.. If you are sure that there is no problem in your manifest.xml then Here is a solution...
1)Delete Android.3.1 or which version folder you have from c/User/Android.your version...
2)Then start Android again..
It worked for me..
I had the same problem.
Try this: In Android Studio Tool Bar -> select Run->Edit Configuration-> On Launch Option ->Select Nothing in place of Default Activity
I have been doing my research, but I feel as if I am missing something.
I have an app with a login. Each time you open the app, you should be forced through that login page. You should never be able to resume onto any activity other than the login.
In the manifest I have
android:clearTaskOnLaunch="true"
on the main activity I wish to use as the login activity,
and
android:finishOnTaskLaunch="true"
as well as
android:excludeFromRecents="true"
on the rest of the activities.
The problamatic situation occurs when you go from the login to another activity, hit home, and relaunch the app via the icon. It should jump back to the login page, but it doesnt. Any idea?
I have also been installing as a regular apk, not via eclipse as I know that there is an issue with eclipse and some of the manifest attributes.
Perhaps if there is a way to detect that the activity launch came from the app icon press, I could manage it that way, but I dont think that is possible either.
In either onResume or onRestart you could check a series of flags, such as a login timeout, then force the user back to the login activity using an Intent, while at the same time finishing the original activity.
I like this method in favor or just finishing the app in either onPause or onStop because it gives you a chance to make some checks before blindly closing the application.
Or, you could try using the android:noHistory tag in your manifest file.
A value of "true" means that the activity will not leave a historical trace. It will not remain in the activity stack for the task, so the user will not be able to return to it.
There are also other tags such as, android:finishOnTaskLaunch
Whether or not an existing instance of the activity should be shut down (finished) whenever the user again launches its task (chooses the task on the home screen) — "true" if it should be shut down, and "false" if not. The default value is "false".
More information here: http://developer.android.com/guide/topics/manifest/activity-element.html
The easiest and fastest way is probably to terminate the activity with finish(); in its onPause() since this is invoked when the App is put into the background.
It might be possible to solve with XML configuration as well, but not that I know of by heart.
i am iOS app developer. Now when i created an app on iOS i want to do the same on android. With java i was familiar just now need some time to remember.
i was looking at some tutorial how to do one or other things. But what i can't find is the basics how everything works. How classes is interacting with each other.
For example i want to create registration window with few buttons and alerts.
I want registration window to be called just once when app is installed and just that.
Should i create new java class and few layouts, one for View with buttons and other for Alerts ?
Or should i create other class for alerts if i need them in other flow of my app ?
And how i should call that window with registration from my main class, which is
extends Activity
Also if there are some developers who came this road from objective-c (iOS) to java (android). It would be nice for some share experience how they did that.
Thank you for any help :)
Very few of the concepts in iOS and Android are similar. On Android you have Activites, Intendts the Manifest. When you design your layout it should be resolution independent. You have a search, back and a menu button and variable hardware. All of this has no equivalent in iOS.
That said, I think you just have to read the basic concepts and the getting started guide no matter if you come from iOS or never have done mobile development before.
EDIT
To answer your concrete question. Take a look at the lifecycle of an Activity and Preferences. With this, you could do some action on the first start of your main Activity and store some flag in the preferences when it's done. On the next start you just test that preference and skip the logic.
You can create one activity (.java file) and one layout(.xml file with buttons and input boxes) , alerts could be toast notifications:
http://developer.android.com/guide/topics/ui/notifiers/toasts.html
All you require for this is a activity and a layout xml for that activity, this activity will be your main ie the entry point to your application, in that activity oncreate method you can check if it is registered or not by setting a flag or something which will direct to the next activity if its registered.
GOOD LUCK...
Just like your nibs in iPhone you create xml layouts in Android. And for view controllers here you make activity. One important thing is AndroidManifest.xml file, it contains all information of your app (like plist) plus all the activity information(Intent type and launcher methods).
This must be an easy one but I'm not having much luck searching for an answer.
Apologies if this is a regular question.
If I navigate away from my app I cannot return to it. Starting the app again will load a second instance of it rather than returning to it. If I leave an audio loop running in my app, It's hard to get back in and turn it off.
On startup I'd like the app to destroy any previous instance of itself left running.
I'd also like to try having the app shut itself down when I navigate away (I know it's not the right way to do things but I'd like to try this for my own personal use of the app). Or have the "back" button destroy the app.
Thanks.
Add this to your activity definition in manifest...
android:launchMode = "singleInstance"
How to prevent the activity from loading twice on pressing the button
I have answered such a question,you can declare android:launchMode="singleTask" attribute for your MainActivity in the AndroidManifest.xml file, so that the OS won't create a new instance if there is one running in the background.
This is an Android noob question.
I am trying to start an activity of another apk through my own application. Now I know I can launch any other application and invoke its main activity. In many cases I'm also able to start subactivities, for example display it's settings dialogue.
However with some applications, for example Facebook or Endomondo I would get a FC everytime I try to launch some specific activity of their application.
Now I suspect that this is a permission issue and that the Facebook or Endomondo devs just don't want other applications to get access to their activities. But do I have to find out which activities I can use and which ones I can't use by trial and error every single time?
Plus: Is there any way around this dilemma? Maybe on a rooted device?
Cheers for any pointers.
As you already said you can only use activities of other apps which are designed to be used by others applications. Normally the developer of the other app define a set of intents and actions their app will be able to understand and process.
Using any other app's activity is by default not possible, this is by design of Android as every app runs in it own sandboxed process (there are some exceptions where apps can share a process).
So to use another app's activities you must know the intents it listen on. Normally this can be found in the applications website or documentation or on OpenIntents a dictionary for intents.