Go Back   Android Forums > Android Development > Application Development > Developer 101

Developer 101 101 Tutorials



Reply
 
LinkBack Thread Tools
Old July 22nd, 2010, 09:45 AM   #1 (permalink)
Junior Member
 
Join Date: Jul 2010
Posts: 27
 
Device(s):
Thanks: 11
Thanked 0 Times in 0 Posts
Post New to developing (internship) having some problems/ignorance related

I have started an internship and picked up a few books that I have been following to try and put a simple application together for the business. Unfortunately, I am relatively new to java and completely new to application development so I am looking for any kind of help.

The basic idea of the application is to be able to show users closed banks (rss feed), a overview of recent failures (rss feed) and send them to a form on a website.

So I layed out a splash screen, then the menu would have 3 buttons, 2 to rss feeds and one to the form on the website.

Everything was going well until I couldn't figure out how to get from the splash screen to the menu.


I don't know what you need to look at so here is the manifest, splash xml and splash java.


Splash Xml.
Code:
<?xml version="1.0" encoding="utf-8"?>



<RelativeLayout android:id="@+id/RelativeLayout01" xmlns:android="http://schemas.android.com/apk/res/android" android:clipChildren="false" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@android:color/white"><TextView android:id="@+id/TextView01" android:text="@string/txt1" android:textColor="@color/loadtxt" android:layout_width="fill_parent" android:textSize="18pt" android:textStyle="bold" android:layout_height="wrap_content" android:gravity="top|center" android:paddingTop="12px"></TextView><ImageView android:id="@+id/ImageView01" android:layout_width="fill_parent" android:layout_height="fill_parent" android:scaleType="fitCenter" android:src="@drawable/logoooo"></ImageView><ViewAnimator android:layout_height="wrap_content" android:id="@+id/ViewAnimator01" android:layout_width="wrap_content" android:layout_above="@+id/ImageView01"></ViewAnimator><TextView android:id="@+id/TextView02" android:layout_height="wrap_content" android:text="@string/txt2" android:textColor="@color/loadtxt" android:textSize="12pt" android:layout_width="fill_parent" android:gravity="center" android:layout_above="@+id/TextView03"></TextView><TextView android:id="@+id/TextView03" android:layout_height="wrap_content" android:text="@string/txt3" android:textColor="@android:color/black" android:textSize="5pt" android:gravity="bottom|center" android:layout_alignParentBottom="true" android:layout_width="fill_parent"></TextView>





</RelativeLayout>
Splash Java
Code:
package android.bankclosures;

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

public class SplashActivity extends Activity {
    protected boolean _active = true;
    protected int _splashTime = 5000;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);
        
       // thread for displaying the Splash Screen
        Thread splashThread = new Thread() {
            @Override
            public void run(){
                try {
                    int waited = 0;
                    while(_active && (waited <_splashTime)) {
                        sleep(100);
                        if(_active) {
                            waited +=100;
                    
                        }
                    }
                } catch(InterruptedException e) {
                    // do nothing
                } finally {
                    finish();
                    startActivity(new Intent("android.bankclosures.Menu"));
                    stop();
                }
            }
        };
        splashThread.start();
            
        
        }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            _active = false;
        
        }
        return true;
    }
        }
Manifest

Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="android.bankclosures"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:label="@string/app_name" android:debuggable="true" android:enabled="true" android:icon="@drawable/logoooo">
        

    <activity android:name=".SplashActivity" android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
       
</activity><activity android:name="MenuActivity" android:label="Menu"></activity>
</application>
    <uses-sdk android:minSdkVersion="8" />

</manifest>

Anything would be helpful as it is clear I am completely new and lost. I have done tutorials in the book and am frankly desperate. Also signed up for the app generator stuff that just came out but havent heard anything and don't know if there's any real app generator that wouldn't run me 800$ to build something this simple.

Thanks
Siggi

sigurros is offline  
Last edited by sigurros; July 22nd, 2010 at 10:17 AM. Reason: wrap code
Reply With Quote
Sponsors
Old July 22nd, 2010, 10:12 AM   #2 (permalink)
Member
 
Join Date: May 2010
Location: West Des Moines, IA
Posts: 105
 
Device(s):
Thanks: 9
Thanked 12 Times in 11 Posts
Default

Try not calling finish() before startActivity(...)

And use the code tags when displaying code so it's readable :P (there's a button with # on it)
andywhoa is offline  
Reply With Quote
The Following User Says Thank You to andywhoa For This Useful Post:
sigurros (July 22nd, 2010)
Old July 22nd, 2010, 10:17 AM   #3 (permalink)
Junior Member
 
Join Date: Jul 2010
Posts: 27
 
Device(s):
Thanks: 11
Thanked 0 Times in 0 Posts
Default

thanks for the code wrap, will try your suggestion and post back
sigurros is offline  
Reply With Quote
Old July 22nd, 2010, 11:48 AM   #4 (permalink)
Senior Member
 
Join Date: Jul 2010
Posts: 616
 
Device(s): Samsung Galaxy S II, HTC Evo 4G, Amazon Kindle Fire
Thanks: 0
Thanked 74 Times in 67 Posts
Default

Also, in splash java, there is really no need to put that in a new thread. just doing all of that in the UI thread would be fine.
jonbonazza is offline  
Reply With Quote
Old July 22nd, 2010, 12:36 PM   #5 (permalink)
Junior Member
 
Join Date: Jul 2010
Posts: 27
 
Device(s):
Thanks: 11
Thanked 0 Times in 0 Posts
Post still having problems

I moved the finish() to different places, still cant figure why it wont work. Any suggestions on where to move it/other reasons why I can't get from the splash screen to menu screen?

Or maybe if there is a simple code to just keep the splash up for 2-5 seconds then go to menu screen I can find somewhere?
sigurros is offline  
Reply With Quote
Old July 22nd, 2010, 12:49 PM   #6 (permalink)
Senior Member
 
Join Date: Jul 2010
Posts: 616
 
Device(s): Samsung Galaxy S II, HTC Evo 4G, Amazon Kindle Fire
Thanks: 0
Thanked 74 Times in 67 Posts
Default

How to: Create a splash screen on Android Development
jonbonazza is offline  
Reply With Quote
Old July 23rd, 2010, 07:22 AM   #7 (permalink)
Junior Member
 
Join Date: Jul 2010
Posts: 27
 
Device(s):
Thanks: 11
Thanked 0 Times in 0 Posts
Default

This is where I got the info from, the finish() is before the startActivity in there. It's actually a copy from that tutorial. Yet still I can not transition to the menu page
sigurros is offline  
Reply With Quote
Old July 23rd, 2010, 08:47 AM   #8 (permalink)
Member
 
Join Date: Sep 2009
Location: Birmingham, UK
Posts: 148
 
Device(s): G1 (Developer model), HTC Tattoo, Nexus One.
Thanks: 1
Thanked 26 Times in 22 Posts
Default

Hi sigurros,

What happens when you run the app? Does it show the splash screen? Does it freeze up? Does it crash? If it crashes, what do you get in the log? Can you paste the exception & stack trace if there is one.

If it was my code I'd forget the splash screen for now, and check to see if the menu activity can be started without any of the additional complications. Make the code as simple as possible in order to launch the activity. If it still doesn't work then at least you can rule out the splash screen and thread.

Mark

p.s.

Quote:
Originally Posted by jonbonazza View Post
Also, in splash java, there is really no need to put that in a new thread. just doing all of that in the UI thread would be fine.
Are you sure about that?

Doing a loop and sleeping in the GUI thread sounds like a bad idea to me.
The code won't return from onCreate() until the loop finishes.

It's quite possible that the GUI won't be updated until Android gets control back, after you return from onCreate(). In which case the splash screen won't appear.

And in general, keeping a GUI thread busy is considered bad practice, as it'll stop responding to the user.
markb is offline  
Reply With Quote
Old July 23rd, 2010, 09:14 AM   #9 (permalink)
Junior Member
 
Join Date: Jul 2010
Posts: 27
 
Device(s):
Thanks: 11
Thanked 0 Times in 0 Posts
Default RE:

In the emulator (debug run) it shows the splash screen for about 5 seconds and then goes back to the application menu. And I would like to get this to work because I will need to learn how to get from one activity to another for the menu buttons as well, which I again I apologize for being so new to this and seeking help far beyond what I should be trying to do.

Stack
Code:
Thread [<9> Thread-10] (Suspended (exception ActivityNotFoundException))    
    Instrumentation.checkStartActivityResult(int, Object) line: 1408    
    Instrumentation.execStartActivity(Context, IBinder, IBinder, Activity, Intent, int) line: 1378    
    SplashActivity(Activity).startActivityForResult(Intent, int) line: 2817    
    SplashActivity(Activity).startActivity(Intent) line: 2923    
    SplashActivity$1.run() line: 34

If theres any more info I can give you please let me know (and maybe where to find it if this isnt right)
sigurros is offline  
Reply With Quote
Old July 23rd, 2010, 01:58 PM   #10 (permalink)
Member
 
Join Date: May 2010
Location: West Des Moines, IA
Posts: 105
 
Device(s):
Thanks: 9
Thanked 12 Times in 11 Posts
Default

Try changing the finally clause of your try/catch to this:
Code:
Intent intentLaunchMenu = new Intent(SplashActivity.this, MenuActivity.class);
startActivity(intentLaunchMenu);
finish();

Take out the stop(); It's not necessary (and is deprecated) as your thread is about to end.

From the Android documentation on Thread:
Quote:
stop()
This method is deprecated. because stopping a thread in this manner is unsafe and can leave your application and the VM in an unpredictable state.
andywhoa is offline  
Last edited by andywhoa; July 23rd, 2010 at 02:03 PM.
Reply With Quote
Sponsors
Old July 23rd, 2010, 02:06 PM   #11 (permalink)
Member
 
Join Date: May 2010
Location: West Des Moines, IA
Posts: 105
 
Device(s):
Thanks: 9
Thanked 12 Times in 11 Posts
Default

Oh oh, I think I see your problem

You are missing a "." in your manifest before "MenuActivity"
Code:
<activity android:name="MenuActivity" android:label="Menu"></activity>
to
Code:
<activity android:name=".MenuActivity" android:label="Menu"></activity>
This is needed because the name gets added to the package name. Currently yours would compile android.bankclosuresMenuActivity instead of android.bankclosures.MenuActivity.


Try doing what I've told you in my last two posts and see if that helps
andywhoa is offline  
Reply With Quote
Old July 27th, 2010, 12:25 PM   #12 (permalink)
Junior Member
 
Join Date: Jul 2010
Posts: 27
 
Device(s):
Thanks: 11
Thanked 0 Times in 0 Posts
Default

Oy! Thank you. Got it to work. If I have another problem I will definetly post back, a forum that helps!
sigurros is offline  
Reply With Quote
Old July 28th, 2010, 01:23 PM   #13 (permalink)
Junior Member
 
Join Date: Jul 2010
Posts: 27
 
Device(s):
Thanks: 11
Thanked 0 Times in 0 Posts
Default

Anyone know a link to writing a button that links to rss feed?
sigurros is offline  
Reply With Quote
Reply

Bookmarks


Go Back   Android Forums > Android Development > Application Development > Developer 101 User CP
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Few Phonebook Related Problems. Tommyj Hero - Support and Troubleshooting 0 September 2nd, 2010 08:28 AM
two really anoying problems, might be related jelte12345 HTC Desire 2 August 22nd, 2010 09:08 PM
HTC Hero - Two problems, might be related Andyc655 Android Lounge 1 June 6th, 2010 07:39 PM
Astro, Zilliow, Facebook Problems/Froyo Related? TitanAlum Incredible - Support and Troubleshooting 0 May 27th, 2010 12:19 PM
pardon the ignorance davewoodson HTC Passion 3 December 11th, 2009 12:04 AM



All times are GMT -5. The time now is 06:23 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Custom vBulletin Skins by: Relivo


SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.