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


Last Updated:

  1. sigurros

    sigurros Active Member This Topic's Starter

    Joined:
    Jul 22, 2010
    Messages:
    27
    Likes Received:
    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 (Text):
    1. <?xml version="1.0" encoding="utf-8"?>
    2.  
    3.  
    4.  
    5. <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>
    6.  
    7.  
    8.  
    9.  
    10.  
    11. </RelativeLayout>
    12.  
    Splash Java
    Code (Text):
    1. package android.bankclosures;
    2.  
    3. import android.app.Activity;
    4. import android.os.Bundle;
    5. import android.view.MotionEvent;
    6. import android.content.Intent;
    7.  
    8. public class SplashActivity extends Activity {
    9.     protected boolean _active = true;
    10.     protected int _splashTime = 5000;
    11.  
    12.     /** Called when the activity is first created. */
    13.     @Override
    14.     public void onCreate(Bundle savedInstanceState) {
    15.         super.onCreate(savedInstanceState);
    16.         setContentView(R.layout.splash);
    17.        
    18.        // thread for displaying the Splash Screen
    19.         Thread splashThread = new Thread() {
    20.             @Override
    21.             public void run(){
    22.                 try {
    23.                     int waited = 0;
    24.                     while(_active && (waited <_splashTime)) {
    25.                         sleep(100);
    26.                         if(_active) {
    27.                             waited +=100;
    28.                    
    29.                         }
    30.                     }
    31.                 } catch(InterruptedException e) {
    32.                     // do nothing
    33.                 } finally {
    34.                     finish();
    35.                     startActivity(new Intent("android.bankclosures.Menu"));
    36.                     stop();
    37.                 }
    38.             }
    39.         };
    40.         splashThread.start();
    41.            
    42.        
    43.         }
    44.  
    45.     @Override
    46.     public boolean onTouchEvent(MotionEvent event) {
    47.         if (event.getAction() == MotionEvent.ACTION_DOWN) {
    48.             _active = false;
    49.        
    50.         }
    51.         return true;
    52.     }
    53.         }
    Manifest

    Code (Text):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    3.       package="android.bankclosures"
    4.       android:versionCode="1"
    5.       android:versionName="1.0">
    6.     <application android:label="@string/app_name" android:debuggable="true" android:enabled="true" android:icon="@drawable/logoooo">
    7.        
    8.  
    9.     <activity android:name=".SplashActivity" android:label="@string/app_name">
    10.             <intent-filter>
    11.                 <action android:name="android.intent.action.MAIN" />
    12.                 <category android:name="android.intent.category.LAUNCHER" />
    13.             </intent-filter>
    14.        
    15. </activity><activity android:name="MenuActivity" android:label="Menu"></activity>
    16. </application>
    17.     <uses-sdk android:minSdkVersion="8" />
    18.  
    19. </manifest>
    20.  

    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
     

    Advertisement
  2. andywhoa

    andywhoa Well-Known Member

    Joined:
    May 15, 2010
    Messages:
    105
    Likes Received:
    13
    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)
     
    sigurros likes this.
  3. sigurros

    sigurros Active Member This Topic's Starter

    Joined:
    Jul 22, 2010
    Messages:
    27
    Likes Received:
    0
    thanks for the code wrap, will try your suggestion and post back
     
  4. jonbonazza

    jonbonazza Well-Known Member

    Joined:
    Jul 13, 2010
    Messages:
    1,934
    Likes Received:
    458
    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.
     
  5. sigurros

    sigurros Active Member This Topic's Starter

    Joined:
    Jul 22, 2010
    Messages:
    27
    Likes Received:
    0
    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?
     
  6. jonbonazza

    jonbonazza Well-Known Member

    Joined:
    Jul 13, 2010
    Messages:
    1,934
    Likes Received:
    458
  7. sigurros

    sigurros Active Member This Topic's Starter

    Joined:
    Jul 22, 2010
    Messages:
    27
    Likes Received:
    0
    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
     
  8. markb

    markb Well-Known Member

    Joined:
    Sep 14, 2009
    Messages:
    148
    Likes Received:
    26
    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.

    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.
     
  9. sigurros

    sigurros Active Member This Topic's Starter

    Joined:
    Jul 22, 2010
    Messages:
    27
    Likes Received:
    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 (Text):
    1. Thread [<9> Thread-10] (Suspended (exception ActivityNotFoundException))    
    2.     Instrumentation.checkStartActivityResult(int, Object) line: 1408    
    3.     Instrumentation.execStartActivity(Context, IBinder, IBinder, Activity, Intent, int) line: 1378    
    4.     SplashActivity(Activity).startActivityForResult(Intent, int) line: 2817    
    5.     SplashActivity(Activity).startActivity(Intent) line: 2923    
    6.     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)
     
  10. andywhoa

    andywhoa Well-Known Member

    Joined:
    May 15, 2010
    Messages:
    105
    Likes Received:
    13
    Try changing the finally clause of your try/catch to this:
    Code (Text):
    1. Intent intentLaunchMenu = new Intent(SplashActivity.this, MenuActivity.class);
    2. startActivity(intentLaunchMenu);
    3. 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:
     
  11. andywhoa

    andywhoa Well-Known Member

    Joined:
    May 15, 2010
    Messages:
    105
    Likes Received:
    13
    Oh oh, I think I see your problem

    You are missing a "." in your manifest before "MenuActivity"
    Code (Text):
    1. <activity android:name="MenuActivity" android:label="Menu"></activity>
    to
    Code (Text):
    1. <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
     
  12. sigurros

    sigurros Active Member This Topic's Starter

    Joined:
    Jul 22, 2010
    Messages:
    27
    Likes Received:
    0
    Oy! Thank you. Got it to work. If I have another problem I will definetly post back, a forum that helps!
     
  13. sigurros

    sigurros Active Member This Topic's Starter

    Joined:
    Jul 22, 2010
    Messages:
    27
    Likes Received:
    0
    Anyone know a link to writing a button that links to rss feed?
     

Share This Page

Loading...