Change the View

by and . modi » Tue, 11 Nov 2008 05:08:01 GMT


Sponsored Links
 Hi,
I am developing a game.
When the game starts, it shows one screen (Splashscreen).I have
created xml file for that which contains only backgroudn. Nothing
else.

I want that after some time (2 sec proabably), it should switch to the
new view, which shows the menu for the game. Now I have created xml
for that also.
What I want is
[1] When view for menu loads, and if user presses back, user should
not get that splashscreen back.
[2] The view should be changed automaticlly (from splash to menu). And
I m not sure, that how can I do this. I googled and what I found is I
have to create activities for each views and create diffrent java file
for that and use Intent to call the view, But I don't find any code
that properly explain this.

If any can throw some light on this, it will be really helpful.
P.S. I m doing this for my college project.

Thanks in advance.

--~--~---------~--~----~------------~-------~--~----~



Change the View

by Dennis W. » Tue, 11 Nov 2008 10:34:37 GMT


 I think, a thread is usefull to switch from your splash screen to the
main menu. To fix your first problem, I've got no idea, unfortunately.

public class SplashScreen extends Activity {

    private static final String TAG = "SplashScreen";
    private static final int MAIN_MENU_ID = Menu.FIRST;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash_screen);

        class SleepClass implements Runnable {
            public void run() {
                try {
                    Log.i(TAG, "loading application");
                    Thread.sleep(3000); // wait 3 seconds
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                Intent myIntent = new Intent(SplashScreen.this,
YourMainApplication.class);
                startActivity(myIntent);
            }
        }

        Thread t1 = new Thread(new SleepClass());
        t1.start();
    }
}



--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Change the View

by Mark Murphy » Tue, 11 Nov 2008 13:32:47 GMT


 


1. You can use ViewFlipper to hold both the splash screen and the menu 
in the same layout file. Then, in onCreate(), use View#postDelayed() to 
trigger a switch to the menu after so many seconds.

2. You apparently can call setContentView() multiple times without 
problems, though I have not tried this. So, in onCreate(), you would 
call setContentView() for the splash screen, then use View#postDelayed() 
to call setContentView() for the menu.

In either case, you have a single activity.

I have a blog post up describing the ViewFlipper technique, though it is 
for an older SDK and may require fixes to the poorly-formatted source code:

 http://androidguys.com/?p=654 

ViewFlipper also makes it easy to set up custom animations for 
transitioning from the splash screen to the menu.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com 
_The Busy Coder's Guide to Android Development_ Version 1.4 Published!

--~--~---------~--~----~------------~-------~--~----~



Change the View

by [EMAIL PROTECTED] » Fri, 14 Nov 2008 03:46:49 GMT


 i,
I use code as shown by you. But the problem is that I am not getting
the screen shown by main.xml file (first screen).
When I press back button from the screen viewed by menu.xml file
(second view), it shows view by main.xml file (so it is there but
doesn't come up). So now I don't understand why it doesn't come up in
first place.


The code is as follows:

package com.naag;

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

import android.view.Window;
public class naag extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);

//No Title bar will be displayed
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);

class SleepClass implements Runnable
{
public void run()
{
try
{
Thread.sleep(10000); // wait 10 seconds but not
getting this..
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
}

Thread t1 = new Thread(new SleepClass());
t1.start();

Intent menuLauch = new Intent (this, menu.class);
startActivity (menuLauch);

}
}


The problem is I am not getting delay of 10 second.
I provided delay in menu.java file for 2 sec and it is there.

The menu.java file is as follows...
package com.naag;

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

public class menu extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);

//No Title bar will be displayed
requestWindowFeature(Window.FEATURE_NO_TITLE);
try {
Thread.sleep (2000); ///////////////////only
getting this
delay
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
setContentView(R.layout.menu);
}
}

I have also changed AndroidManifest.xml to use intents..

Also
What I found more is:
These two lines of code also not working properly.

requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);

When the application starts, only black screen with Title of Game
comes up. After 2 seconds, the view displayed by menu.xml file comes
up. (Actully it should display first screen provided by main.xml and
that is also without Title bar and when I press back button from menu,
it shows main screen without title bar).
So don't uderstand when I am messing up.
-------------------------------------------------------------------------------------------------------------------------------

The viewflipper is a good idea but its not useful in my application.
Thanks for that information.

Also by changing setContentView(R.layout.menu); after setContentView
(R.layout.main); doesn't help.
As it provides only second view and that is without first even show up
and its not there in history stack.

So please help me in this problem.

Thanks for your replies.

On Nov 11, 8:32a



Change the View

by [EMAIL PROTECTED] » Fri, 14 Nov 2008 11:54:37 GMT


 package com.naag;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;

import android.view.Window;
public class naag extends Activity {

        private final int SPLASH_DISPLAY_LENGTH = 2500;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle)
    {
        super.onCreate(icicle);

        //No Title bar will be displayed
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.main);                   //main is the
first view.

                new Handler().postDelayed(new Runnable(){
            @Override
            public void run(){
                 /*Create an Intent that will start the Menu.Activity
*/
                 Intent mainIntent = new Intent( naag.this,
menu.class ); //menu.class is second view
                 naag.this.startActivity( mainIntent );
                 naag.this.finish();
            }
       }, SPLASH_DISPLAY_LENGTH );
    }

};


I used this code and working perfectly fine...

--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. SoundPool doesn't play sounds >100K in SDK 1.5

Hello,

I am trying to use SoundPool class from the new SDK. However, I
discovered that if I load sounds that are >100K (120K and 350K) from
resources I have problems playing them. The error messages that I get
are as follows:

06-23 10:53:42.263: ERROR/AudioFlinger(35): not enough memory for
AudioTrack size=1048640
06-23 10:53:42.263: DEBUG/MemoryDealer(35):   AudioTrack (0x25018,
size=1048576)
06-23 10:53:42.263: DEBUG/MemoryDealer(35):     0: 0002aaf0 |
0x00000000 | 0x00090940 | A
06-23 10:53:42.263: DEBUG/MemoryDealer(35):     1: 0002ab78 |
0x00090940 | 0x0006F6C0 | F
06-23 10:53:42.263: DEBUG/MemoryDealer(35):   size allocated: 592192
(578 KB)

Consequently, the playback never starts.

Curiously, the numbers in the message do not seem to change with sound
files of different sizes: whether it is 120K or 350K, it always says
"not enough memory for AudioTrack size=1048640". Also, when I load the
sounds I see numerous messages in the log saying "06-23 10:53:35.743:
ERROR/AudioCache(35): Heap size overflow! req size: 1052672, max size:
1048576".

So, is there any "official" size limit on the size of the files you
can play, or are there any settings to adjust to solve this problem?
The test application where I get this doesn't actually do anything
else but loads and tries to play these sounds, so I do not think that
it is the problem of it using too much memory overall. I also tried
both .ogg and .mp3 files - equally without any success.

Any help would be much appreciated,

---
Best regards,
Katsiaryna
--~--~---------~--~----~------------~-------~--~----~

2. Where to store data

Hi All,

i'm writing an application that needs to store some small jpeg or
pngs. Looking at the documentation i have seen that databases are
stored under /data/data/package_name/databases
I decided to store my data under /data/data/package_name/files.
With the emulator i can see all these files (databases and images)
under the proposed directories but moving the application on a real
device and installing a file system browser i cannot see any file
under /data. Can anyone explain me why?
My application works perfectly on my mobile (HTC magic) so i think
that data is downloaded and stored.
If this is a security constraint, do i need to put the application
under debug on the mobile in order to inspect file system?
Kind Regards,
          MF
--~--~---------~--~----~------------~-------~--~----~

3. is it possible to support bluetooth OBEX?

4. 3D Streaming on Android Phone?

5. how to use g1's camera application from my application

6. Help: canvas.drawLine(p1.x, p1.y, p2.x, p2.y, paint);

7. ExifInterface and libexif