Search code examples
androidflashsplash-screen

playing .swf on application startup


I want that i play .swf file when the android user clicks on the application icon and the application starts and after that i want to start the application's activity. Here is what i thought and what i have done until now. From http://web.archive.org/web/20130712051340/http://www.androidhive.info/2013/07/how-to-implement-android-splash-screen-2/

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.webkit.WebView;
import android.webkit.WebSettings.PluginState;

public class Splash_Screen extends Activity {
    
     private static int SPLASH_TIME_OUT = 3000;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.startup);
        
        new Handler().postDelayed(new Runnable() {
             
            /*
             * Showing splash screen with a timer. This will be useful when you
             * want to show case your app logo / company
             */
 
            @Override
            public void run() {
                // This method will be executed once the timer is over
                // Start your app main activity
                String localUrl ="file:///android_asset/Kiss-o-meter.swf";

                WebView wv=(WebView) findViewById(R.id.webview);
                wv.getSettings().setPluginState(PluginState.ON);
                wv.loadUrl(localUrl);       
                
                Intent yes_krao = new Intent(Splash_Screen.this, KissingMeter.class);
                startActivity(yes_krao);
                finish();
            }
        }, SPLASH_TIME_OUT);
         
            
    }   
}

Here is my xml file:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
              android:orientation="vertical" 
              android:layout_width="fill_parent" 
              android:layout_height="fill_parent"> 
     
     <WebView android:id="@+id/webview" 
              android:layout_width="fill_parent" 
              android:layout_height="fill_parent"/>

</LinearLayout> 

Is there anything wrong with it?? seems like the code is not working! secondly setPluginsEnabled(true); is also not being picked up by eclipse!


Solution

  • startActivity(yes_krao) is called immediately after you have loaded the WebView so the application will switch Activities before your .swf has a chance to play. One solution would be to implement a Handler and switch Activities after the duration of your .swf file.

    E.g.:

    import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    import android.os.Handler;
    import android.webkit.WebView;
    import android.webkit.WebSettings.PluginState;
    
    public class Splash_Screen extends Activity {
    
         private static int SPLASH_TIME_OUT = 3000;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
            setContentView(R.layout.startup);
    
            String localUrl ="file:///android_asset/Kiss-o-meter.swf";
    
            WebView wv=(WebView) findViewById(R.id.webview);
            wv.getSettings().setPluginState(PluginState.ON);
            wv.loadUrl(localUrl); 
    
            new Handler().postDelayed(new Runnable() {
    
                /*
                 * Showing splash screen with a timer. This will be useful when you
                 * want to show case your app logo / company
                 */
    
                @Override
                public void run() {
                    // This method will be executed once the timer is over
                    // Start your app main activity      
                    Intent yes_krao = new Intent(Splash_Screen.this, KissingMeter.class);
                    startActivity(yes_krao);
                    finish();
                }
            }, SPLASH_TIME_OUT);
        }   
    }
    

    Note that setPluginsEnabled() has been deprecated, so you should use setPluginState():

    WebSettings webSettings = yourWebView.getSettings();
    webSettings.setPluginState(PluginState.ON);