Android :: Handle Screen Orientation Changes With An Activity Started Within A Tab's Activity
Nov 2, 2010
I have a TabActivity, and each Tab corresponds to its own Activity. In one of them, in the onCreate method, I use startActivityForResult to show a dialog (specifically, Bump's BumpAPI activity).
code:...............
The problem is that when the screen orientation changes, it tries to create the tab's activity again which makes another BumpAPI dialog, resulting in multiple stacked on top of each other. Do I have a hook into the started activity to cancel the previous one when the orientation changes?
A workaround seems to be to add a button that when clicked, starts the second activity, but that adds an unnecessary step.
Also, I can't fix the screen orientation for the entire tabActivity because some of them require typing and users may want to use their physical keyboards.
View 1 Replies
Aug 9, 2010
I am writing an activity, that loads data from a server and displays it as a list using ArrayAdapter. For that I'm showing a progress dialog i.e loading, while it loads all data from the server. Then i dismiss the dialog in a handler. My problem is that when ever i change the orientation, the progress dialog is again shown, which is not needed, because all the data is displayed already?
View 1 Replies
View Related
Apr 6, 2010
i've developed an android app that's fetches an xml file and displays this data via several markers on the map. This works fine so far. The problem right now is that when i switch the orientation of the phone (portrait->landscape or vice versa) the markers disappear for a small moment, the xml processing is started again and then they reappear. Is there a way to prevent this re-loading of the file? It only takes about 2-3 seconds.
View 2 Replies
View Related
May 1, 2010
I have following problem with my application: From my main activity ("activity 1"), there is a menu from which user can launch an action. This action will result in an Intent being received by a BroadcastReceiver, defined in my application. Finally, this BroadcastReceiver will start an activity ("activity 2") to deal with this intent.
The problem is that I have a "quit application" entry in my menu, and I can only finish() currently active activity. ie I am not able to finish "activity 1" from the menu of "activity 2". And I can't use startActivityForResult() as "activity 2" can't be started from "activity 1". Any suggestion would be much appreciated Thank you very much guys, regards.
View 4 Replies
View Related
Jan 21, 2010
When views with different type have same id and screen orientation changes,
either java.lang.ClassCastException: android.view.AbsSavedState$1 or java.lang.IllegalArgumentException: Wrong state class -- expecting View State will occur. (depends on the view's order)
Because View.dispatchRestoreInstanceState() checks id only.
You may wonder why anyone would make views with different type to have same id.
But it can happen when you use tab activity.
Imagine you have tab activity with two children activity.
Tab1 is ListActivity and Tab2 is ExpandableListActivity.
Both activity have id of "@android:id/list" but the type of view is different.
This means we cannot use ListActivity & ExpandableListActivit at the same in one tab activity.
View 4 Replies
View Related
Aug 16, 2010
I know on screen orientation changes activity restarted, but suppose i don't want to restart the activity then what should I do? I had tried it by adding in manifest.xml. android:configChanges="keyboardHidden|orientation"
and override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); }
But still activity restarted each time when I change screen orientation.
View 17 Replies
View Related
Nov 12, 2010
Suppose I have something like an alarm activity which launches the alarm through the lock screen, accomplished via
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
Now, from here I could press the back button to kill the activity, but I also want a press of the lock button to silence the alarm. How would I go about creating a handler for presses of the lock screen button?
View 2 Replies
View Related
Nov 2, 2010
I want to display a splash screen followed by my trial.class.I am not getting any error but warning as:
Warning: Activity not started, its current task has been brought to the front
I have different-2 approches for this each time this warning is being displayed.
CODE:.....................
View 8 Replies
View Related
Apr 3, 2010
I'm having difficulties handling multiple instances of my root (main) activity for my application. My app in question has an intent filter in place to launch my application when opening an email attatchment from the "Email" app. My problem is if I launch my application first through the the android applications screen and then launch my application via opening the Email attachment it creates two instances of my root activity. steps: Launch root activity A, press home Open email attachment, intent filter triggers launches root activity A Is it possible when opening the Email attachment that when the OS tries to launch my application it detects there is already an instance of it running and use that or remove/clear that instance?
View 1 Replies
View Related
Mar 12, 2010
I'm trying to find a way to properly handle setting up an activity where its orientation is determined from data in the intent that launched it. This is for a game where the user can choose levels, some of which are int portrait orientation and some are landscape orientation. The problem I'm facing is that setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) doesn't take effect until the activity is fully loaded. This is a problem for me because I do some loading and image processing during startup, which I'd like to only have to do once.
Currently, if the user chose a landscape level:
the activity starts onCreate(), defaulting to portrait discovers from analysing its launching Intent that it should be in landscape orientation continues regardless all the way to onResume(), loading information and performing other setup tasks at this point setRequestedOrientation kicks in so the application runs through onPause() to onDestroy() it then again starts up from onCreate() and runs to onResume() repeating the setup from earlier
Is there a way to avoid that and have it not perform the loading twice? For example, ideally, the activity would know before even onCreate was called whether it should be landscape or portrait depending on some property of the launching intent, but unless I've missed something that isn't possible. I've managed to hack together a way to avoid repeating the loading by checking a boolean before the time-consuming loading steps, but that doesn't seem like the right way of doing it. I imagine I could override onSaveInstanceState, but that would require a lot of additional coding. Is there a simple way to do this?
Solution:
As per Daniel's answer, this was actually quite easy to fix. I just needed to make a few small changes. In my 'menu' Activity, where the player would choose which level to play, I just had to add an if/else check to choose which class would be started by my Intent. This was done with a simple int representing portrait or landscape, determined when the player selected a level. I then created a second class extending my 'GameLogic' class; this is the class which contained most of the code for the game itself, rather than the menus, instructions, etc.
public class GameLandscape extends GameLogic{}
Literally that simple and completely empty. That way it inherited all the code from my previous activity where I had already coded it to handle things differently depending on the orientation. Lastly I just had to add a line to the manifest stating that GameLandscape would always run in landscape, and GameLogic would always run in portrait.
View 2 Replies
View Related
Aug 13, 2010
It seems when screen orientation changes, the activity's onCreate() method is called. In my onCreate() method, I have an AlertDialog which pops up when the activity is called. The problem is when I switch the screen sideways, the popup is displayed again. How can I avoid this?
View 1 Replies
View Related
Nov 24, 2010
In onCreate method of Activity, it binds to a remote service and makes use of AIDL intefaces. Is it required to unbind from the remote service when onDestroy is called on screen orientation change.?
If the activity un-bounded from the remote service in onDestroy and if no other contexts are bound to remote service, is remote service likely to get stopped losing the state that it maintains.?
View 1 Replies
View Related
Aug 29, 2010
I'm testing an app on a Droid. It's a kind of card matching game. I'd like to keep the cards physically located in the same place on the screen regardless of a screen rotation. For example, I can put my thumb on a card, rotate the phone any way I please and the card stays fixed under my thumb. However, the orientation of the content of the card will change to match the current phone rotation. I handle this by transforming the card grid in onCreate. This works fine for 90 degree rotations, but if I do a fast 180 degree flip from one landscape mode to another the screen simply flips and the Activity is NOT destroyed and recreated.
This seems contrary to the documentation:
http://developer.android.com/reference/android/R.attr.html#configChanges
"public static final int configChanges Since: API Level 1
Specify one or more configuration changes that the activity will handle itself. If not specified, the activity will be restarted if any of these configuration changes happen in the system. Otherwise, the activity will remain running and its Activity.onConfigurationChanged method called with the new configuration. "
I am NOT specifying any configChanges in my AndroidManifest.xml file, so it seems that the activity SHOULD be destroyed and recreated. Why isn't it? Is there some way I specify that it should be destroy/ recreated?
View 7 Replies
View Related
May 14, 2009
I have created an activity for my game which handles all orientation changes by itself and has a fixed "portrait" layout. Actually it uses the accelerometer and is rendered using 2D canvas methods. If the level has been completed I show up a highscore dialog in which the user can enter his name. The dialog is floating above the underlying level screen which gets blurred out nicely. This generally works.
Problem is that the dialog does not get rotated if the orientation of the phone changes. So even if the keyboard is exposed the dialog is shown in portrait mode instead of landscape. I have tried to use an activity with dialog theme instead but the behavior didn't change. After several tries it seems that I have found the reason for this: Once there's an activity with fixed orientation in the activity stack then all subsequent activities keep this orientation, too. They will not react on orientation changes anymore (e.g. if the keyboard gets exposed).
After upgrading to 1.5 SDK the described behavior changed a little bit. Now at subactivities indead react on orientation changes like expected. However, the need to have an opaque background! That means that neither dialogs nor activities with dialog theme will work. Those will stick with the orientation of the underlaying activity. So my workaround is to first start a sub-activity with an opaque black background. This activity then shows my highscore dialog on top. It looks quite okay but I wonder if there's a better solution? Is it possible to show a dialog above a fixed portrait or landscape activity which automatically adapts to orientation changes?
View 3 Replies
View Related
Mar 31, 2010
I just want to get numbers of times to be used for each Activity.
So the very straightforward method I thought is increasing the count for an Activity when it was started. But how can I get the information?
View 3 Replies
View Related
Jun 18, 2009
Is there a way to do this?
Can you access the activity stack in a way to grab what activity came before the one now in view?
I have a situation where an activity needs to know where it was started from, so it knows what data to display in that current activity.
View 7 Replies
View Related
Oct 19, 2010
How can I know what Activity has started the current Activity? Is there any specific method like, i.e. getIntent().getCallerActivity() or the only way is saving some information within the Intent using putExtra()?
View 1 Replies
View Related
Mar 3, 2010
example scenario is: from login screen - main screen - then when i clicked a hide button inside the mainscreen, the app will need to go in the home screen, and when im going to click the app again the main screen would be called and not the login screen
View 3 Replies
View Related
Mar 3, 2010
example scenario is: from login screen - main screen - then when i clicked a hide button the app will go to home screen, and when im going to click the app again the main screen would be called.
View 2 Replies
View Related
Jul 16, 2010
I used Toast to make notification, but it seems it will appear even its activity is not in the current screen and some other activity has been started.I want to check this situation, when the activity is not the current one, I'd not send the Toast notification. But how to do ?
View 1 Replies
View Related
Aug 25, 2010
I have a central activity that can be launched from two separate classes. I was hoping that in this central activity I could have an IF statement like
if(this.getIntent() == MainMenu.class)
{
// Do something here
}
But obviously that isn't legal so how could I structure an expression to check from what class an intent was started.
View 2 Replies
View Related
Jun 25, 2010
I have small simple Service and big MainActivity with UI. Service is called periodically from AlarmManager. My Service need to know if MainActivity is on the screen and inform MainActivity about state changing.
View 3 Replies
View Related
Jul 21, 2010
Suppose my application P started Activity A, and A started Activity B, then the activity stack contained A and B, with B at the top.
After that, I opened other apps by pressing Home button. Suppose after a while, the process of application P is killed by the OS. Then, I press Home button to select application P. At this time, which activity will be brought to the front, Activity A or Activity B?
View 1 Replies
View Related
Jun 17, 2010
I've a service which listens to user request for ending one activity and starting another activity. For Ex: Say there are activities1,2 ,& 3. Now if there is already activity1 started by someother activity then based on the user request i need to stop activity1 and start activity2 or activity3. If the acitivity1 is started by my service then i can do finishactivity(requestcode) and shall receive a call to onActivityResult() then i can start next activity 2 or 3. But can i stop the activity1 which is started by some other activity from a service?
View 2 Replies
View Related
Mar 19, 2010
I've successfully implemented a BootReceiver, AlarmManager, and Service per the code here: http://github.com/commonsguy/cw-advandroid/tree/master/SystemServices...
Inside the doWakefulWork method of the Service I am instantiating a few classes, but some of them require my Activity to be running. How do I actually start the Activity? The code above only starts the AlarmManager and Service.
There are also times where the Activity *is* already started, like if the user manually opened it. So I also need to start the Activity "only if it's not already running". Hows that work?
And what about the situation where the user first installs your application and may not even reboot their phone for a week. In that case, do you have to start the Service from the Activity? But then the Service will die with the Activity.
View 7 Replies
View Related
Jun 30, 2010
At the beginning Activity is launched by an Intent and something is done with this Intent. When I change orientation of my Activity, it's reloaded again and Intent is passed to the Activity. How can I clear that Intent to prevent Activity from using it again?
View 1 Replies
View Related
Sep 8, 2010
How to handle Home key....Plzz Help me out.We can handle Home button.if you have seen the Nexus One device...when u reset the phone ..and switch it on again some tutorials kind of thng comes..at that time wen u press the home button its not taking u to the Launche Activity...if its not possible then how they are handling over there.I want the Answer..No one in this Blog has any idea how to handle it....or no one has tried on this..sum are sayng that we can handle it by PhoneWindowManager.java class,some r sayng we can handle it by Using onNewINtent() method.But the Question is how we can handle it by these two ways...Just provide me the sample code..where we are handling the HomeKey.
View 9 Replies
View Related
Sep 13, 2010
I have an Activity that will query a RESTful API every x seconds (polls using a handler). The results of the GET are used to update a ListView. This is done using an AsyncTask.
I want to put a Notification in the Notification bar when certain criteria are met in the new data. Everything I have read up to this point has suggested that notifications should be created and updated using a service so that the notifications can be made even when the application isn't in focus. I see the positive aspects of this.
However, I'm unsure if I should just create a service from within my activity or if I need to do something more complex than that. I'm undecided on if I should scrap my AsyncTask model in favor of using the Service to update my list view.
So, my questions are:
1) Is there a good tutorial showing how to make a local service from an activity?
The tutorial doesn't need to show how to make them communicate, the service could be isolated from the main activity.
2) Will #1 provide me with the notification benefits I'm looking for? (Notifications are generated even when the main app isn't visible)
3) Should I use this same service to update my listview?
The service would basically be making the same query that the AsyncTasks are, just doing different things with the results. The app would seem to make more sense to have the Service query, do notification processing, then give the results to the activity, but I haven't found a good resource that clearly demonstrates how to do something like this.
View 1 Replies
View Related
Apr 11, 2010
I've got an Android application which needs to be woken up sporadically throughout the day.To do this, I'm using the AlarmManager to set up a PendingIntent and have this trigger a BroadcastReceiver. This BroadcastReceiver then starts an Activity to bring the UI to the foreground.All of the above seems to work, in that the Activity launches itself correctly; but I'd like the BroadcastReceiver to notify the Activity that it was started by the alarm (as opposed to being started by the user). To do this I'm trying, from the onReceive() method of the BroadcastReceiver to set a variable in the extras bundle of the intent,Can anyone tell me what's different about passing a bundle from a BroadcastReceiver to an Activity, as opposed to passing the bundle from an Activity to a BroadcastReceiver?
View 2 Replies
View Related
Aug 20, 2010
In my app I want to obtain a gps lock and record the coords. But I do not want to lock the device into looking for the gps. The user is to be free to traverse through the app and the different activities within.
So If I call a locationListener in activity A, can I reference it in activities B C and D?
if is was still in activity A I could say something like
A.this.mlocListener.removeMyUpdates();
When I am in activity B how can I reference the LocationListener I set up in Activity A
View 1 Replies
View Related