• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps New to developing (internship) having some problems/ignorance related

sigurros

Newbie
Jul 22, 2010
27
0
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
 
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?
 
Upvote 0
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.

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.
 
Upvote 0
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)
 
Upvote 0
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:
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.
 
Upvote 0
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
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones