Click Splashscreen causing menu to not work


Last Updated:

  1. sigurros

    sigurros Active Member This Topic's Starter

    Joined:
    Jul 22, 2010
    Messages:
    27
    Likes Received:
    0
    Well with the help of people on this forum I recently completed an application and sent it to my boss to test on a phone. (I do not own an android phone :mad: )

    Anyways when he launched the app it wouldn't work if he clicked the splash screen during its load, meaning the menu buttons would not load the webpages they were intended to. However, if he just let the splash run its course, the app worked fine.

    Any ideas??? Because I am not sure where the problem lies, code is posted below for splash screen, menu, and manifest.

    Splash Screen
    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;// time to display splash screen in ms
    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.                 } catch(InterruptedException e) {
    31.                     // do nothing
    32.                 } finally {
    33.                     Intent intentLaunchMenu = new Intent(SplashActivity.this, MenuActivity.class);
    34.                     startActivity(intentLaunchMenu);
    35.                     finish();
    36.                 }
    37.             }
    38.         };
    39.         splashThread.start();
    40.        
    41.        
    42.         }
    43.  
    44.     @Override
    45.     public boolean onTouchEvent(MotionEvent event) {
    46.         if (event.getAction() == MotionEvent.ACTION_DOWN) {
    47.             _active = false;
    48.        
    49.         }
    50.         return true;
    51.        
    52.     }
    53.        }
    54.            
    55.        
    56.    
    57.  
    Menu
    Code (Text):
    1. package android.bankclosures;
    2.  
    3. import android.app.Activity;
    4. import android.content.Intent;
    5. import android.os.Bundle;
    6. import android.view.View;
    7. import android.view.View.OnClickListener;
    8. import android.webkit.WebView;
    9. import android.widget.Button;
    10.  
    11.  
    12. public class MenuActivity extends Activity implements OnClickListener{
    13.     WebView mWebView;
    14.     WebView mWebView1;
    15.     WebView mWebView2;
    16.     WebView mWebView3;
    17.     Button Button01;
    18.     Button Button02;
    19.     Button Button03;
    20.     Button Button04;
    21.  
    22.     /** Called when the activity is first created. */
    23.     @Override
    24.     public void onCreate(Bundle savedInstanceState) {
    25.         super.onCreate(savedInstanceState);
    26.         setContentView(R.layout.menu);
    27.        
    28.        Button01=(Button)findViewById(R.id.Button01);
    29.        Button02=(Button)findViewById(R.id.Button02);
    30.        Button03=(Button)findViewById(R.id.Button03);
    31.        Button04=(Button)findViewById(R.id.Button04);
    32.        Button01.setOnClickListener(this);
    33.        Button02.setOnClickListener(this);
    34.        Button03.setOnClickListener(this);
    35.        Button04.setOnClickListener(this);
    36.     }
    37.                
    38.        
    39.         public void onClick(View v) {
    40.             Intent intentLaunchActivity;
    41.            
    42.             if(v == Button01)
    43.             {
    44.                 intentLaunchActivity = new Intent(MenuActivity.this, Clsdbanks.class);
    45.                 startActivity(intentLaunchActivity);
    46.             }
    47.             else if(v == Button02)
    48.             {
    49.                 intentLaunchActivity = new Intent(MenuActivity.this, Press.class);
    50.                 startActivity(intentLaunchActivity);
    51.             }
    52.             else if(v == Button03)
    53.             {
    54.                 intentLaunchActivity = new Intent(MenuActivity.this, Form.class);
    55.                 startActivity(intentLaunchActivity);
    56.             }
    57.             else if(v == Button04)
    58.             {
    59.                 intentLaunchActivity = new Intent(MenuActivity.this, News.class);
    60.                 startActivity(intentLaunchActivity);
    61.                 finish();
    62.             }
    63.         }  
    64. }

    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.       <uses-permission android:name="android.permission.INTERNET" />
    7.     <application android:label="@string/app_name" android:enabled="true" android:icon="@drawable/logonobg" android:debuggable="false">
    8.        
    9.  
    10.     <activity android:name=".SplashActivity" android:label="@string/app_name">
    11.             <intent-filter>
    12.                 <action android:name="android.intent.action.MAIN"/>
    13.                 <category android:name="android.intent.category.LAUNCHER" />
    14.             </intent-filter>
    15.        
    16. </activity><activity android:name=".MenuActivity" android:label="Menu">
    17. </activity>
    18.  
    19.  
    20. <activity android:label="Closed Banks" android:name=".Clsdbanks"></activity>
    21. <activity android:label="Press" android:name=".Press"></activity>
    22. <activity android:name=".Form" android:label="Help Form"></activity>
    23. <activity android:name=".News" android:label="RK News"></activity>
    24. </application>
    25.     <uses-sdk android:minSdkVersion="4" />
    26.  
    27.  
    28. </manifest>
     

    Advertisement
  2. sigurros

    sigurros Active Member This Topic's Starter

    Joined:
    Jul 22, 2010
    Messages:
    27
    Likes Received:
    0
    When clicking the back button for the last button on the menu page, it closes the application.
     
  3. sigurros

    sigurros Active Member This Topic's Starter

    Joined:
    Jul 22, 2010
    Messages:
    27
    Likes Received:
    0
    Let me know if I need to post any other code.
     
  4. jonbonazza

    jonbonazza Well-Known Member

    Joined:
    Jul 13, 2010
    Messages:
    1,934
    Likes Received:
    458
    The latter problem is caused by this part:

    Code (Text):
    1.  
    2. else if(v == Button04)
    3.             {
    4.                 intentLaunchActivity = new Intent(MenuActivity.this, News.class);
    5.                 startActivity(intentLaunchActivity);
    6.                 finish();
    7.             }
    8.  
    remove finish(); and it should work.
     
    sigurros likes this.
  5. sigurros

    sigurros Active Member This Topic's Starter

    Joined:
    Jul 22, 2010
    Messages:
    27
    Likes Received:
    0
    Do I need that to have the app end though? (I don't know how android phones work.)

    Any clue about the splash problem?
     
  6. jonbonazza

    jonbonazza Well-Known Member

    Joined:
    Jul 13, 2010
    Messages:
    1,934
    Likes Received:
    458
    If you want to have a manual option to close your app (normally this is handled by the activity lifecycle), you need to put an exit button or an exit menu item (the usual approach), and call finish() from there. Doing it in a button that is used over and over again is not good, as it will close the activity as soon as you use it once.
     

Share This Page

Loading...