problem in activity and view

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

problem in activity and view

Postby ShanuSaxena » Thu Jan 22, 2009 12:21 pm

Hi all,
my game is in landscape modeby default, done wid setRequestedOrientation(0). in onCrete() our view is getting instanitiated before setContentView()....but every time i slide for keyboard my view is getting reinstanciated,.....is der ne way to avoid this n continue to previous state of view.....


can ne1 plz give me sample code where there's config or savedinst is used for this.....
Attachments
ASDF.java
(682 Bytes) Downloaded 69 times
Change is the law of success. Always Smile :)
ShanuSaxena
Junior Developer
Junior Developer
 
Posts: 18
Joined: Tue Jan 06, 2009 8:28 am
Location: mumbai, india

Top

Postby Emmanuel7 » Fri Jan 23, 2009 12:18 am

The simplest way is to specify the orientation in your manifest :


Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  <activity android:screenOrientation="landscape" android:name="Name">
  2.  
Parsed in 0.000 seconds, using GeSHi 1.0.8.4

So sliding the keyboard won't have an effect anymore !


See the documentation here :
http://code.google.com/android/reference/android/R.styleable.html#AndroidManifestActivity_screenOrientation
Emmanuel7
Senior Developer
Senior Developer
 
Posts: 164
Joined: Fri Dec 12, 2008 2:17 am
Location: Paris

Postby ShanuSaxena » Fri Jan 23, 2009 5:58 am

thanx for repling,....

problem is not wid landscape mode its working fine.........but wenever i slide open the keyboard my activity reinitialises my view n game starts form main screen....... is der any way to stop calling onCreat again n agin wen i slide open/close k/b
Change is the law of success. Always Smile :)
ShanuSaxena
Junior Developer
Junior Developer
 
Posts: 18
Joined: Tue Jan 06, 2009 8:28 am
Location: mumbai, india

Postby MrSnowflake » Fri Jan 23, 2009 5:59 am

When changing orientation, the Activity gets destroyed and recreated again. If you have a game, you could probably implement the orientation change by changing your rendering orientation, instead of having the activity being destroyed.
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

thanx for reply

Postby ShanuSaxena » Fri Jan 23, 2009 6:13 am

orientation is in landscape by default......but while opening n closing of k/b activity is being recreated causing completly renewing my view.....is der ne way to stop activity to recreate??
Change is the law of success. Always Smile :)
ShanuSaxena
Junior Developer
Junior Developer
 
Posts: 18
Joined: Tue Jan 06, 2009 8:28 am
Location: mumbai, india

Postby MrSnowflake » Fri Jan 23, 2009 6:35 am

Yeah, so, why won't Emmanuel7's sollution work then?
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Top

Postby ShanuSaxena » Fri Jan 23, 2009 6:48 am

yeah i've done dat.....but still activity still recreates as i slide open or close the keyboard.......game starts in lanscpe but if accidently user opens k/b den game wl restart....we want to avoid dat......
Change is the law of success. Always Smile :)
ShanuSaxena
Junior Developer
Junior Developer
 
Posts: 18
Joined: Tue Jan 06, 2009 8:28 am
Location: mumbai, india

Postby ShanuSaxena » Fri Jan 23, 2009 7:46 am

hey guys i got this....was easy really but der ws some prob wid my eclips dats y i was getting prob......nw after cleaning proj n restarting eclips its running fine........trick is to add android:configChanges="orientation" in mainfest xml so onCreate is not called again n again after changing orien.....it'll call onConfigurationChanged instead of onCreate........


thanx for taking intrest in probbb.................. :D
Change is the law of success. Always Smile :)
ShanuSaxena
Junior Developer
Junior Developer
 
Posts: 18
Joined: Tue Jan 06, 2009 8:28 am
Location: mumbai, india

Postby Emmanuel7 » Fri Jan 23, 2009 1:49 pm

Good to know you find a solution !

But I'm surprised, I though adding the android:screenOrientation="landscape" in your manifest would prevent the onCreate to be called.
My understanding was that this parameter set how Android decides to trigger a "Orientation has changed" trigger ( whether you deal with it or no ).
Setting it to unspecified ( default value ) let the keyboard sliding decide of the orientation
setting it to sensor let the real orientation decides
And I though setting it to landscape would never launch the trigger !

Are you sure it does not work ? ( i don't have the real device ... )
Emmanuel7
Senior Developer
Senior Developer
 
Posts: 164
Joined: Fri Dec 12, 2008 2:17 am
Location: Paris

Postby ShanuSaxena » Wed Jan 28, 2009 11:35 am

hey sry for late reply....ya it works fine......in xml u hv 2 add android:configChanges="orientation | keyboardhidden" ....u'll hv to check spelling of "keyboardhidden"....i tried it on actual cell G1.....

adding android:screenOrientation="landscape" in your manifest wont stop onCreate call everytime u slid open or close....
Change is the law of success. Always Smile :)
ShanuSaxena
Junior Developer
Junior Developer
 
Posts: 18
Joined: Tue Jan 06, 2009 8:28 am
Location: mumbai, india

Hi Guys,

Postby rajendrakumar » Wed Jan 28, 2009 5:13 pm

what Emmanual told is rt..

But you can do one more thing for this orentation problem...

When you use "configChanges" in your manifest file. When the system config changes it will trigger the new configuration to Configuration.

If you want two diffrent kind of xml screen fo your application (lanscape and portrait),

You can design it.


by invoking this following method in your Activity,


public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}

You must call the super.onConfigurationChanged(newConfig), then only your activity will react for this..

and you can check the orientation like this and you can do what ever you want for the change,



@Override
public void onConfigurationChanged(Configuration newConfig) {

if (Configuration.ORIENTATION_LANDSCAPE == newConfig.orientation){
// Do your change
}else if (Configuration.ORIENTATION_PORTRAIT== newConfig.orientation){
// Do your change
}
};


It should work.. But not yet tested.....



Regards,
Rajendrakumar chinnaiyan.
rajendrakumar
Developer
Developer
 
Posts: 40
Joined: Thu Jan 01, 2009 7:57 am

Postby ShanuSaxena » Thu Jan 29, 2009 7:22 am

yup dats wat i've done.....it works fine on device.....
Change is the law of success. Always Smile :)
ShanuSaxena
Junior Developer
Junior Developer
 
Posts: 18
Joined: Tue Jan 06, 2009 8:28 am
Location: mumbai, india

Hi ShanuSaxena

Postby rajendrakumar » Thu Jan 29, 2009 3:57 pm

Could you post the code what you have done in that methods..

Its not working for me in the device...

So am struggling here...

How to set the layout in this Onconfig cahange methods.....


In my case the method it self not invoking....

So tell me how you did that...????
rajendrakumar
Developer
Developer
 
Posts: 40
Joined: Thu Jan 01, 2009 7:57 am

Postby ShanuSaxena » Fri Jan 30, 2009 6:49 am

here's the code.....check logcat for result
below is xml





<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="andro.orienTest" android:versionCode="1"
android:versionName="1.0.0">
<application android:icon="@drawable/icon"
android:label="@string/app_name">
<activity android:name=".oriTest"
android:label="@string/app_name"
android:configChanges="keyboardHidden|orientation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Attachments
oriTest.java
(1.58 KiB) Downloaded 74 times
Change is the law of success. Always Smile :)
ShanuSaxena
Junior Developer
Junior Developer
 
Posts: 18
Joined: Tue Jan 06, 2009 8:28 am
Location: mumbai, india

Hi ShanuSaxena

Postby rajendrakumar » Fri Jan 30, 2009 6:54 am

Ok that's fine..

Your not changing the Layout of the file rt......

Can any one tel me how to chang the layout when the Configuration changed method is Invoked...
rajendrakumar
Developer
Developer
 
Posts: 40
Joined: Thu Jan 01, 2009 7:57 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 4 guests