Posts Tagged Android Manifest

Android application don’t fill all (screen) display area on HTC Sensation

Recently I wrote some app which looks good on HTC Desire and looks bad on HTC Sansation. The application didn’t fill all screen (display) area. And I see some black parts of display when I run my application.

Here the screenshot:

HTC Sansation. Android application don't fill all screen (display) area

HTC Sansation. Android application don't fill all screen (display) area

To fix this I made some changes in Android Manifest file. I’ve added next code in manifest node.

<supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true"/>

Tags: , , ,

How to set the different screen orientations for TabActivity children activities

Hi,
Here I want to show you how to make different screen orientation for TabActivity children activities.

You may say “Just specify this in Android Manifest file. That’s All”. But, it didn’t works. All child activities have same orientation with parent (TabActivity).

Below you can download source code of Android project

I will show you how I fix this for me.

  1. Specify the portrait or some else orientation for TabActivity in Manifest file. This will be default orientation for all child activities.
  2. Save reference to TabActivity as static field in TabActivity class
  3. Download the source code below. Pay attantion in onPause and onResume methods in SecondTabActivity class.
The code is so simple :)

TabActivitySampleActivity.java

package com.hrupin;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;

public class TabActivitySampleActivity extends TabActivity {
	
	private static TabActivitySampleActivity INSTANCE;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        INSTANCE = this;
        TabHost host = getTabHost();
        
        TabSpec tab1 = host.newTabSpec("tab1");
        tab1.setIndicator("TAB 1");
        tab1.setContent(new Intent(this, FirstTabActivity.class));
        
        TabSpec tab2 = host.newTabSpec("tab2");
        tab2.setIndicator("TAB 2");
        tab2.setContent(new Intent(this, SecondTabActivity.class));
        
        host.addTab(tab1);
        host.addTab(tab2);
    }
    
    public static TabActivitySampleActivity getInstance(){
    	return INSTANCE;
    }
}

FirstTabActivity.java

package com.hrupin;

import android.app.Activity;
import android.os.Bundle;

public class FirstTabActivity extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.first);
	}
}

SecondTabActivity.java

package com.hrupin;

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.os.Bundle;

public class SecondTabActivity extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.second);
	}
	
	@Override
	protected void onResume() {
		super.onResume();
		TabActivitySampleActivity.getInstance().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
	}
	
	@Override
	protected void onPause() {
		super.onPause();
		TabActivitySampleActivity.getInstance().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
	}
}

Download the source code Here  you can download the source code of Android project

Tags: , , , ,

Hire me!