Keep Screen On & Change Orientation

by naxtek » Thu, 12 Feb 2009 00:19:10 GMT

Sponsored Links
 Hi - After some help with this.

I am making an Android app which is currently coming along nicely -
I've hit upon a couple of stumbling blocks.

1) How do I stop the screen from going dim/off and the phone locking
while the application is running?

2) Can I force the phone to enter landscape mode on running my

Andrew :)

Keep Screen On & Change Orientation

by Dianne Hackborn » Thu, 12 Feb 2009 01:57:35 GMT

 There is a flag in WindowManager.LayoutParams you can set to keep the screen
on.  (Please do NOT use the lower-level PowerManager class for this.)

Use android:screenOrientation on the activity in your manifest to force a
particular orientation mode.

Dianne Hackborn
Android framework engineer

Note: please don't send private questions to me, as I don't have time to
provide private support.  All such questions should be posted on public
forums, where I and others can see and answer them.


Sponsored Links

Other Threads

1. Would you at least give us names

I know you have plans, but at least share with us who won in round 1.
Some of us have plans and need to know if they lost so they can start
selling their app or otherwise wait and keep their app free.
Instead of keeping thousands of users in the dark, announce the 200
and let others start planning.

This is really annoying, it's been almost three weeks and you won't
give information, you're delaying the release of the thousands of
application because of this! most developers will be annoyed when they
find out they lost and that they were waiting in vain.


2. OnLocationChanged never called

Hello there! I'm trying to create a simple app to test GPS
integration. Using the emulator and geo fix commands from telnet I'm
able to get it working as expected. But installing it on a device,
when I click on the first button to start listening for updates I can
see the the GPS is active (by the small radar icon) but, moving
around, It never updates the textfields it were suppose to update.

Any ideas?


import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.sax.TextElementListener;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends Activity {
    /** Called when the activity is first created. */

      private boolean amIListening = false;

    public void onCreate(Bundle savedInstanceState) {
        Button btn = (Button)this.findViewById(;
        Button btn2 = (Button)this.findViewById(;

        final LocationManager lm = (LocationManager)getSystemService
        final LocationListener gpsListener = new MyGPSListener(this);

        btn.setOnClickListener(new OnClickListener() {

                        public void onClick(View v) {
                                        lm.requestLocationUpdates("gps", 5000, 
0, gpsListener);
                                        amIListening = true;

        btn2.setOnClickListener(new OnClickListener() {

                        public void onClick(View v) {
                                        amIListening = false;


    private class MyGPSListener implements LocationListener{

        private Activity activity;

        public MyGPSListener(Activity parent){
                this.activity = parent;

                public void onLocationChanged(Location location) {
                        Double lat = location.getLatitude();
                        Double lon = location.getLongitude();
                        Double alt = location.getAltitude();
("Latitude: " + lat);
("Longitude: " + lon);
("Altitude: " + alt);

                public void onProviderDisabled(String provider) {
                        // TODO Auto-generated method stub


                public void onProviderEnabled(String provider) {
                        // TODO Auto-generated method stub


                public void onStatusChanged(String provider, int status, Bundle
extras) {
                        // TODO Auto-generated method stub



3. Modular packaging - Queries

4. ContentResolver in a Service

5. Will Android apps every make proper money ...

6. make seekbar (un)clickable depending on RadioButton

7. ListViews in tabs