Android :: Setting Activity Orientation By Code?

Nov 24, 2010

It is possible to set the orientation of an activity in the manifest file. but is it also possible to do it from code? if so, how?

Android :: setting activity orientation by code?


Android :: Setting Preferred Home Activity From Application Code

Jan 7, 2010

I'm trying to have my home-screen application register itself as the default home-screen so the user is not prompted with the IntentResolver's list of all the available home-activities.

This is my code:

CODE:.................

I have the android.permission.SET_PREFERRED_APPLICATIONS set in the manifest. After executing the code above, the logs claim things have been added like expected (same logs as when I tick off "Make default" from IntentResolver's list). However, when I proceed by clicking home, the list still shows up and the logs say:

CODE:.....................

So it seems the resolver deletes the default entry. Am I doing something wrong, or is this a security measure? What are the ideas behind this?

View 2 Replies View Related

Android :: Orientation Change - Dialog Above Activity With Fixed Orientation

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

Android :: Orientation Change Crash In Tab Activity With List Activity

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

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 View Related

Android :: Activate The Setting Option Orientation?

Mar 9, 2010

Generally, there should be an option named Orientation which is in Setting -> Sound and Display -> Display setting -> Orientation

However, I can't not see the option "Orientation" in the Android. How could I activate this option?

View 5 Replies View Related

Android :: Accelerometer / Orientation For Rolling Ball Code?

Mar 23, 2009

If I'm reading things right, the accelerometer measures physical forces (i.e. movement) and the orientation sensor gives the tilt of the handset. If you are coding a rolling ball type app which would you use? You could argue accelerometer, in which case you measure each delta force and apply it to your balls physics. Or just the orientation and compute the effects of gravity again on the ball but just using different physics. Is there a preference? Would any be more accurate than the other?

View 3 Replies View Related

Android :: How To Handle Activity When Orientation Changes?

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

Android :: How Does My Activity Knows When The Device Changes In Orientation

Sep 20, 2010

How does my android activity know (is there a callback) when there is a change in screen orientation?

View 1 Replies View Related

Android :: On Screen Orientation Changes Activity Restarted

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

Android :: Handling Orientation Changes That Occur In Another Activity

Jun 3, 2010

I am having an interesting problem and would appreciate any advice. My app uses WebView as its primary view. Using a javascript hook, it can launch the camera so the user can take a picture. The camera is launched using: Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

When the camera starts, it makes sense to use landscape mode, so the user naturally turns the phone on its side. After the user takes a picture, control returns to my launching Activity (actually, my Acitivity gets restarted because it usually gets destroyed to free up memory for the camera on my Moto Droid). When my WebView gets recreated, I restore its state from the Bundle I saved in onSaveInstanceState().

Now everything looks ok, except the phone is still in landscape mode. However, when the user turns the phone upright bringing back into portrait mode, my WebView takes up only half of the screen. Somewhere along the way, the scale of my WebView got lost. This seems like such a minor issue, but it is driving me crazy.

Does anyone have an idea why this might be happening? What is the correct way to preserve the scale of my WebView? I am hesitant to hard code any scale factors because what looks good on my device may not be the same for another.

View 8 Replies View Related

Android :: Changing Orientation Resets Activity

Jul 7, 2009

I finally got to the point where I was ready to deploy my app to my G1 and test it out and the first thing I noticed was that when I change my phone to landscape view my main activity restarts and resets all of my variables to their default settings. How can I avoid this?

View 7 Replies View Related

Android :: Need To Temporarily Disable Orientation Changes In An Activity

Aug 31, 2010

My main activity has some code that makes some database changes that should not be interrupted. I'm doing the heavy lifting in another thread, and using a progress dialog which I set as non-cancellable. However, I noticed that if I rotate my phone it restarts the activity which is REALLY bad for the process that was running, and I get a Force Close.

What I want to do is programatically disable screen orientation changes until my process completes, at which time orientation changes are enabled.

View 3 Replies View Related

Android :: Maintaining State Of Activity On Orientation Change

May 6, 2010

I m currently working on landscape mode for android app in which i want to know how to maintain the state of the activity and views displayed on orientation change i.e from portrait mode to landscape mode ?

View 3 Replies View Related

Android :: Activity Being Killed - OnDestroy - On Orientation Change

Apr 5, 2010

I am working on a MVC implementation for Android (to be subsequently hosted on SF and/or GC).

It works like this:

Activity (View) <=> Application (Controller) <=> Data (Model) <=> Persistence (DB/Network etc)

The scenario is:

1. Activity launch (main/launcher)

2. Notifies Application about performing a data transaction

3. Upon receipt of data response, controller devices which Activity to launch (or update existing)

4. Application has overridden the method onConfigurationChange

Problem: When the orientation is changed, the Application is notified about onConfigurationChange but:

a) The "current" activity is Destroyed and recreated -- which is fine to some extent b) The new instance which is created is automatically => onCreate, onPause, onStop, onDestroy.... now that's catastrophic.

View 4 Replies View Related

Android :: Prevent Rotation/change Of Orientation In Certain Tab/activity

Sep 11, 2010

My MainActivity (the one that is started by the android application) is a TabActivity which contains several tabs (which are implemented as activities as well). In a certain tab/activity I want to prevent the change of orientation/rotation when the phone is turned. What is the easiest way to achieve this?

View 2 Replies View Related

Android :: Background Activity For Map Started Again When Orientation Change

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

Android :: Can I Temporarily Disable Automatic Orientation Changes In My Activity

May 26, 2010

Can I temporarily disable automatic orientation changes in my Activity? I want to do this when my app does some background internet communication.

View 1 Replies View Related

Android :: ListView In Activity Getting Refreshed On Changing Orientation

Apr 7, 2010

I have Activity with ListView inside it and in the onCreate method of the Activity I have code for populating the Data of the ListView this Data is a server based and so populating includes calling Network URLs. I have the ArrayAdapter of the ListView in the Same Activity Class.

Now the Issue I'am facing is that, in Rest all scenarios my Activity is behaving in a proper way but when the Orientation [ Portrait to Landscaped or other way round] is taking place the Data is Getting lost and Newer Data calls are Required to Populate the Same Old Data now this is something that is not intended out the code how should I deal with it.

View 4 Replies View Related

Android :: Refresh RelativeLayout When Orientation Changes Without Restarting The Activity?

Jun 7, 2010

I have an Android Activity with a RelativeLayout and I have implemented the following method to prevent the activity from being recreated on change of Orientation:

CODE:..............
I am obviously not doing anything in this method, but it worked perfect when using a LinearLayout. Now however, using RelativeLayout, my layout is all messed up when changing to landscape orientation.

What is the most efficient way to have the screen redraw correctly without having the activity restarted again with a call to onCreate?

View 2 Replies View Related

Android :: Setting Wallpaper Through Code

Jun 14, 2010

I was trying to make an app which also had the facility to let user select wallpaper he would like to set. I have managed this by calling the Gallery Intent. Once the user selects a specific image, the data path of the image is returned to me which then i preview to the user by setting the image onto an imageview.

The problem crops up when the image size (and/or resolution) is greater than what android expects. This results in failure of my module.

And as if this was not enough, wen the user tries to select some other wallpaper(and in my test case the "other" wallpaper was also of size >700kb) then the app crashes with the "OutOfMemoryException"...

For Gallery Intent i use:

CODE:............

For setting the wallpaper i use:

CODE:.......

So i have 2 problems to deal with:

How to crop the image before setting it as wallpaper...Cant understand y OutOfMemoryException is thrown, coz none of my image sizes exceed even 1mb... and i guess the VM budget in case Of N1 is 24Mb if m not mistaken...

View 1 Replies View Related

Android :: Setting Up Code For Different Runtimes

Oct 18, 2010

I am working on an Android application that is supposed to run on Android 1.5 and later devices. I am using RawContacts.CONTENT_URI enumeration for registering a ContentObserver in my application subclass. Now, RawContacts was introduced in Eclair and running this code on Android devices having runtime less than 2.0, gives java.lang.VerifyError. For older devices, I have to use Contacts.CONTENT_URI.

So to fix this, I've put something like the following in my code:

CODE:.......

I am still getting java.lang.VerifiyErrors.

How do I setup my code for different runtimes?

View 1 Replies View Related

Android :: Handling Screen Orientation Change During Activity Start

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

Android :: DIP Scale And Setting Values In Code

Jul 7, 2009

I have read about using a 'dip' scale rather than just px, this is straightforward to implement in XML. But how do I adjust values accordingly in the java code? For example:

tv.setTextSize(20)

will result in text of size 20 px right? What's the quickest way of making this 20 dip, other than adding a resource?

View 3 Replies View Related

Android :: Setting Different Browser Homepage Through Code Possible?

Jun 12, 2009

Can I set a different Browser Homepage through code? If so then how? Need info about this urgently.

View 5 Replies View Related

Android :: Void Activity Destruction (orientation Or During Incoming Phone Call)

Aug 3, 2009

I have a requirement where I have to read/parse some data from the server(using HTTPConnection) and then display it on to the screen. To avoid ANR issue I used AsyncTask to perform the above. Now in order to avoid application crash in case the activity gets destroyed(either by OS or if orientation changes or say on any incoming call-->where user stays on the phone for long and for some reason OS destroys/recreates the activity). Currently, I hols the reference of AsyncTask in my activity and then provide a callback(the activity itself) to AsyncTask so that I can pos back message to activity(like closing progress dialog box).In order to avoid memory leaks on onPause I nullify this activity reference in AsyncTask.Before onPause I save the AsyncTask instance using onSaveInstanceState method but I have to use putSerializable for that. I have read on the forums that serialization method is slow, so my question is should I use parcelable approach(and whether the converting AsyncTask to parcelable will be same as creating any other object parcelable). or both these approaches are totally wrong i.e...............

View 10 Replies View Related

Android :: Show AlertDialog On Activity Start - But Not On Screen Orientation Change

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

Android :: Unbind Remote Service In OnDestroy Of Activity On Screen Orientation Change

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

Android :: Change Orientation Of Android SlidingDrawer By Code?

Jul 17, 2009

I cant find a way to set the orientation on my SlidingDrawer when i change from landscape mode to portrait mode visa versa. Initially i set the orientation by xml to vertical. I need to change the orientation to horizontal when the phone is in landscape mode, so i get the handle on the left.

View 2 Replies View Related

Android :: Clear Defaults By Code - After Setting Use By Default For This Action

Mar 10, 2009

I'm playing with the alternative Home app that comes with the SDK.

I can set this as default for 'Home' action.

I can unset this by -->Setting->Manage Application->My Alternative Home-> "clear defaults"

Question:

How to do this "clear defaults" by code?

I've browsed the forums but cannot find an answer.

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved