I am currently writing an Android app to work as an activity launcher.
The main activity works as launcher and will let users launches a new activity from the main activity(here I create this new activity using FLAG_ACTIVITY_NEW_TASK and FLAG_ACTIVITY_MULTIPLE_TASKS).
So that I can hold multiple these activities with the same name but different content in the background.
But I still need a method to manage them, which means I can offer a UI for user to choose to restart one and kill one.
Can someone give me a good solution?
I appreciate your help very much!
And you can also view a similar question asked by me yesterday: set unique identifier for RunningTaskInfo
You need to get the list of Activity instances which are running in your application. List of all of the activities in our application that are running on the device gives an answer how to do this.
Related
Lets say you've made a messaging app. The main activity would present different contacts and give you options for sharing, messaging, voice-calling, etc. Would each of those options have separate classes all stemming from the main activity class file? If so, would linking those classes into main activity be as easy as creating a method stub in the main activity to open those activities/classes for each option pressed?
I don't think that it's a good idea to use only one Activity for your Application.
Because in android an activity is a single, focused thing that the user can do. Almost all activities interact with the user.
I suppose that for options you want to have a different UI and different user interaction.
So i think that you should use multiple activity's for you options.
To find more information about Activity's check the link:
http://developer.android.com/reference/android/app/Activity.html
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.
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.