Android :: LaunchModes - SingleTask - Switch Between Screens - Intents Only Way
Jan 9, 2010
In a number of questions (like this one) I have been looking into how to "change screens" in my app. I have a "header" on top, with 4 buttons. Each button is meant to replace the "content" (ie change screen):
+--------------------+
| menu with buttons |
+--------------------+
| |
| |
| C O N T E N T |
| |
| |
+--------------------+
When I click a Menu button, I run the following code:
CODE:..............
As you can see, the startActivity is executed. Now, if I do not specify "launchMode" for the Activity that means that launchMode = normal. If launchMode == normal that means that the Activity will be re-created each and every time I navigate using the top header buttons, and that means that all data entered in "form elements" are gone (or at least hidden).
So, I found the launchMode "singleTask" that sounded sort of nice. If I add that launchMode to my Activity, it will not be re-created when I navigate with the buttons, thus keeping state. Great! Well, until I read this:
As noted above, there's never more than one instance of a "singleTask" or "singleInstance" activity, so that instance is expected to handle all new intents.
I found out that the sentence mean that there can be only one Activity that has the launchMode set to "singleTask" - if I have more than one it wont work (no compiler error though).
This means that I can only "keep the state" for one Activity, when switching back and forth (navigating) between my screens!
View 3 Replies
Jun 14, 2010
I have been getting some lag on my droid incredible. Does anyone else get lag if they switch the screens with the optical trackball? If I switch homescreens back and forth with the trackball I get glitchy lag. Also the app tray is laggy. I also notice lag in the game doodle jump. Whats causing this.
View 2 Replies
View Related
Sep 28, 2009
My android app contains a suite of mini apps. In short, the main screen contains several icons, one each for the mini apps. When an icon is clicked, the mini app is launched.
In total I have 4 mini apps. So you could imagine that my main screen is like the Home Screen Launcher. Although these mini apps could run standalone by their own, I want the user to be authenticated. Thus there is a LoginActivity right before the MainActivity.
CODE:.........
I'm still not pretty sure of the benefit of Tasks (arranged set of Activities), so I would like comments from Android experts on my design decisions:-
(1) I plan to set the attribute finishOnTaskLaunch to true for LoginActivity. As I understand it, once the login is authenticated, I will navigate the user to MainActivity, and I want LoginActivity to disappear. Is this better than calling #finish on the Activity ? Will MainActivity automatically become the root of the Task without any extra configuration/code ?
(2) One of the mini app is an IM client. The PresenceListActivity will hosts many instances of ChatActivity (one-to-one chat session with an active contact in the buddylist). I plan to use the default launchmode for ChatActivity since each Chat should be handled by a new instance. Sounds correct ?
(3) A sticky navigation bar will exists in the top corner of AppOneActivity, AppTwoActivity etc.. I plan to set the clearTaskOnLaunch attribute to true for all of them. As I understand it, I should clear the stack whenever I plan to launch into any of the mini apps. Also their launchModes will be singleTask. Am I on the right path ?
(4) Finally I don't really understand how to read the output of adb shell dumpsys activity. For example
CODE:.......
Sometimes underneath the Tasks, you will see History and in others Running, what do these mean ? Even stranger, sometimes I have two History under a task.
View 1 Replies
View Related
Jul 18, 2010
If I am using LauncherPro and want to switch back to the original home screens..........how would I go about doing that? I don't want to uninstall.......just switch back for a bit.
Are the widgets sizeable and customizable in LauncherPro?
View 3 Replies
View Related
Jun 15, 2010
I've been getting this error near constantly the past day whenever I hit the Home button, and when the ui is working it's extremely slow to switch between screens. I can get the error near 100% of the time by opening an applicatio, then hitting the Home button. Then HTC Sense closes, sits at "loading" for a bit, then the phone is back to normal, albeit slow, till the next time I hit Home.
I had been running a live wallpaper of the Earth rotating in the background, and notice it rotates fine for about 3 seconds, pauses, then starts again, so something is eating up the processor I'd think?
I've uninstalled all recently installed applications. Stopped the live wallpaper. Stopped Locale. Stopped background sync, then turned it back on. Installed a task killer to see if there's a common element (none). Tried leaving the battery out for a minute.
View 4 Replies
View Related
Nov 7, 2009
I have some code that is creating and removing alarms, and which works great in Android 1.5 and 1.6 but breaks on the Android 2.0 AVD.The code that's giving this exception is: Code...
View 3 Replies
View Related
Sep 10, 2010
I've been learning Android and have come across an issue with launchMode="singleTask". The documentation states that when this attribute is used, the Activity is always launched into a new task as the root Activity. Secondly, the documentation states that if an Intent is targeted at such an Activity when there are Activities sitting above it in its task stack, such Intents are discarded (although the task is still brought to the foreground).I've been playing around with this, and the behaviour I observe is completely different. In particular:
- Activities with launchMode="singleTask" are not always the root Activity in a task stack. They are just plonked ontop of the existing stack with the same affinity.
- When an Intent is targeted at such an Activity and there are other Activities above it in the stack, the Intent is not discarded. Instead the Activities above it in the stack are discarded. The Intent is then delivered via onNewIntent to the Activity as normal.
Can someone confirm that this is the actual behaviour? If so, why are the documents incorrect? If not what have I done wrong.
View 1 Replies
View Related
Nov 12, 2010
I have an application that runs in the background, and displays an error message via the notifications system. This notification has a pendingIntent that leads back the the app's main screen. On this main screen, I have set launchmode="singleTask". As I understand it from the Android Dev Guide, this should mean that my main activity will only ever have one instance.However, if the user is viewing that activity at the time (or another one within the app), and goes and touches the notification to clear it, it goes ahead and puts another copy of the activity on the stack, so if I hit the back button, it will return to the main screen again (from the main screen).
View 2 Replies
View Related
Mar 31, 2010
I have an app with two activities, one of which the launchmode is set to "singleTask". From the Android dev guide, I got the impression that my SingleTaskActivity should start a new task (or reuse an old task) and always sit at the root of the stack when launched.
However, it's inconsistent with the behavior of the app if I follow the steps below: - launch StandardActivity from home - click the "home" key - launch SingleTaskActivity from home, you will see it's in the foreground as expected - click the "Back" key, StandardActivity comes to the foreground whereas I expect to see the home screen because SingleTaskActivity is supposed to be at the ROOT of the stack. It appears SingleTaskActivity was launched into the task that StandardActivity started, rather than starting its own task.
Is my understanding about the "singleTask" launch mode correct?
=== The Android Dev guide (http://developer.android.com/guide/topics/ manifest/activity-element.html#lmode) says:
In contrast, "singleTask" and "singleInstance" activities can only begin a task. They are always at the root of the activity stack. Moreover, the device can hold only one instance of the activity at a time — only one such task.
CODE:.....................
View 5 Replies
View Related
Sep 16, 2009
In the documentation it is stated that an activity with launchMode="singleTask" is always at the root of the sctivity stack. However, when I run my "singleTask" activity for a few scenarios and monitors behaviour with "adb shell dumpsys activity" I can see it placed both at the top of the stack (with numActivities=2) and in the middle of the stack (with numActivities=3). The activity at the root (frontOfTask=True) has a "normal" launchMode.Is the documentation incorrect or am I missing something?
View 5 Replies
View Related
Feb 18, 2010
I have an activity, ActivityA, and its launchMode is set to "singleTask".I start the application from the app tray. ActivityA launches ActivityB from a button click. ActivityB is a normal activity with no launchMode set ("standard").With ActivityB on top of the activity stack, I hit the home button, then resume the app, I see ActivityA instead of ActivityB when resumed.Shouldn't the history stack be preserved in this case, and B be showing? When I resume, I see A get onNewIntent() called, and I'm not sure why this is happening. I thought the stack would be preserved.
View 1 Replies
View Related
Apr 22, 2010
So I have a MapActivity that runs an asynchtask that occasionally updates what exactly it's displaying on the map (via a string). I originally pass this string in from the intent when the activity is first created. And then if you click on one of the drawables on the map, it opens a new activity, which can then create a new mapview (same class) with a different string setting. The problem I have is that I only want one instance of the mapview to be running at once. Thus I set android:launchmode="singletask" in the manifest. This works in that it brings the mapactivity to the front, but is there any way to send it a new intent bundle to get a new setting for the string it needs? I tried regetting the extras from the bundle, but it seems to retain the old bundle, not the new intent that was passed to it. I'm not sure I want to do startActivityForResult because the 2nd activity may or may not want to update the original activity. I hope that made sense. I can post code if necessary, but I think that should explain my situation.
View 2 Replies
View Related
Oct 13, 2009
Our application which consists of something like this: Main menu => View contacts => Edit contact => View groups => Settings => Browser settings
I have then added gestures so that the user can jump between any of these screens with a gesture. But this leads to a huge activity stack that just grows and grows so how should I properly implement this?
I thought about the following: Main menu (SingleTask) => View contacts (SingleTop) => Edit contact => View groups (SingleTop) => Settings (SingleTop) => Browser settings (SingleTop)
If I do nothing then I end up with something like this (using gestures): Main menu - View Contacts - Main Menu - Browser Settings - View Contacts - Main menu
I would guess this would lead to memory issues sooner or later?
View 5 Replies
View Related
Jun 23, 2009
I've come across a very annoying problem, which only seems to happen when I launch my app from eclipse for testing. If I launch it normally, it doesn't seem to have this problem.
This is how I can reproduce it: - Launch app via Eclipse - Press Home - Relaunch app via icon - Click menu->exit which tells the Service to clean up and calls finish () when the Service finishes cleaning up
For some reason, there seem to be two instances of the activity, one exits normally and the other one gains focus. Clicking exit does nothing since the Service has stopped but the Service variable is not null. Attempting to use the app launches errors since the resource it uses have been closed. I can force a close via the crash and relaunch the app, and it exits normally this time.
As I said, it only happens when launching the app via Eclipse. Anyone know what could cause this? My launchMode is set to singleTask, however, that shouldn't cause an issue, I used that mode before. I tried calling finish() regardless of the state of the Service, but it doesn't seem to help.
View 5 Replies
View Related
Feb 17, 2010
I'm not sure why onPause() is not called in the following scenario.
Here's my activity:
CODE:.......................
View 3 Replies
View Related
Jul 27, 2010
I had a little time with the captivate today and noticed it has 4(i think) horizontal scrolling screens for apps. What happens when you fill those? Does it automatically add another one or what?
View 2 Replies
View Related
Oct 30, 2010
I have an IntentService that broadcasts an Intent each time if finishes some work. Each broadcast Intent is identical except that it contains a Bundle with some result information from the IntentService. Evidently, having different data in the Bundle is not enough for Android to think it's a different Intent. If the IntentService broadcasts two of these Intents back-to-back, the second one is dropped as a duplicate.
I know I've read about this behavior in this forum in the past but I can't find in the documentation where this duplicate elimination logic is described in detail. Mostly, I just want to differentiate the Intents enough that they are not considered duplicates. Any pointers would be appreciated.
View 13 Replies
View Related
Mar 9, 2010
I've a succession of 2 Intent: Intent intent = new Intent(); intent.setClass(EntryPoint.this, MainClass.class); startActivity(intent);
And I'd like an animation (which is present in res/anim) occurs during the transition between these 2 Intents...
View 2 Replies
View Related
Aug 15, 2010
I have a auto-complete textbox in which the user makes a selection. From here I want to load a tabbed layout which is based on the user selection. The problem is I cant figure out a clean way to pass that selection to each of the tabs. At the moment I can pass an intent to the 'tabhost' activity and then pass to each child activity explicitly, however this just seems like messy iterative code to me! So basically how can I pass my intent data bundles to the tabs activities cleanly & efficiently! Psuedo code is also very welcome.
View 2 Replies
View Related
Aug 7, 2010
I am trying to create intents that will be set using alarmmanager. Currently, I can do this with one intent, add extra data to it (strings, but i send them as one string with a seperator), and everything works fine and goes off at the correct time. However, when I try to send multiple intents like this, they are overwritten and only one goes off at the correct time. How can i structure my intents so that they appear different to the alarmmanager (i think they are getting deleted when filterIntent() is run).
long story short- putExtra() makes all the intents look the same still... how can i make them look different so they wont get deleted (and keep track of them in case i want to delete a specific one)
View 2 Replies
View Related
Oct 27, 2010
I want to received the Android broadcast, is there a list of all intents?
View 2 Replies
View Related
Nov 17, 2010
I have searched and searched and I just can't get this code to work. I have a main.xml layout and a setting.xml. I have some values I would like the Settings.class to change in my main apps class.Three string to be exact. I have tried this simple test code in my main app class.
settings.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
Intent intent = new Intent(v.getContext(), Settings.class);
startActivityForResult(intent, 0);}});
//Then a function
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent){
super.onActivityResult(requestCode, resultCode, intent);
Bundle extras = intent.getExtras();
String value = extras.getString("myKey");
if(value!=null){
Log.d("hmmm",value);}}}
In my settings.class I have the following
returnHome.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.putExtra("myKey", "YEAH");
setResult(RESULT_OK, intent);
finish();}});
Back in main app class it is not getting logged. Like I said I have three string in the main class that I want settings class to change and send back.
View 2 Replies
View Related
Apr 6, 2010
On the market, there's an application called App Protector, which seems to effectively block the launching of configured activities until a password is correctly provided. By default, it blocks access to itself (not very interesting), Settings, and a few others. I wrote my own app to launch settings (rather than doing so through the home screen) and App Protector continued to do the job it claims to do.
When an activity that is protected is started, App Protector's password input activity is shown instead. Once the correct password is provided, the activity that was started comes to the front.
First -- does anyone know how this app is able to get between the rest of the system and the activities it protects? I would like to do something along these lines in my own application as well. Perhaps this app is receiving a broadcast about other activities coming to the foreground, and when the foreground activity is protected, it forces itself to the foreground?
Second -- does anyone know how well this technique will stand up to attack? Are there other ways to circumvent, where start Activity(...) fails to? It seems that one could use adb to un install it, thus removing its protection easily, but if I pursue my plans here, the app will be a part of a device's firmware (which, I assume, offers some protection against its apps being installed?)
View 2 Replies
View Related
Aug 10, 2010
Found similar examples--not exactly what I need. I simply need to start messaging (SMS) and email intents from my app with their "to" fields already populated. So I need to send a number with the sms intent and an email address with the email intent.
View 1 Replies
View Related
Sep 19, 2010
Developers. I am a newbie to Android but a seasoned developer in UI, Java , and ECLIPSE. I am trying to do something I believe is very simple yet I am struggling. I have two tabs, A & B. I want to put an Activity in each tab. I want to have the 'B' Activity live inside 'A' so I can access it within 'A'. 'A' has a clock and every second that passes I need to update information in 'B', even if 'A' is not currently shown. I put 'B' into the 2nd tab as follows:TabSpec mapInfo=tabs.newTabSpec("tag3"); Intent intent = new Intent(this, MathleteMapActivity.class)mapInfo.setContent(intent); mapInfo.setIndicator("Course Map");tabs.addTab(mapInfo); I am totally confused on how to get the "MathleteMapActivity" Activity from the Intent 'intent'. There appears no way to do this. Can anyone please recommend a cleaner way to do this knowing what I am trying to do?
View 4 Replies
View Related
Aug 9, 2010
I am implementing a simple app. I need to start an activity based on the state of the Activity. Lets take i am using a button to start the activity.
1. If the activity is not started, I need to start XYZ activity.
2. If the XYZ activity is on focus, then i need to close the activity on the button press.
3. If the XYZ activity is not in focus (like onPause) state then, I need to change the button state.Can you please help me in the flags that i need to use for starting the intent. Is it possible to get the state of activity before I start that activity?
View 2 Replies
View Related
May 26, 2010
Working with android I realized that implicit intents are good choice in most of cases due to their's flexibility. But what's about explicit intents? What are benefits of using them? What are common cases when it's a good practice to use them?
View 1 Replies
View Related
Jan 8, 2010
I have two applications A and B (in different packages,but it doesn't matter).Application B is an sms application that i have made and contains one activity.This activity has a method called sendSMS(String number,String text).I want to call this method from application A and send an SMS without opening the activity(the GUI) of application B but just send an SMS in the background by calling just the method of the activity.Any ideas?
View 10 Replies
View Related
Jul 14, 2010
I have few intents in my manifest file and an AIR application. How can I instantiate AIR application from android.
View 3 Replies
View Related
Jun 28, 2010
I have an app that has two buttons one for email & one for SMS. Depending on the button pressed I want to email or else SMS a certain text. I have coded the email button and it is working fine. The problem is that the dialog box that pops-up gives an option of e-mail or Messaging the text. I want to separate out the two, so that when the user presses email, only the options of email is there, and when the user presses SMS, only the option of Messaging is there.
View 1 Replies
View Related