0

I am not able to change starting activity of application. In starting my starting activity was com.example.image_changer.MainActivity and with this my application run correctly. Then I change my launching activity from MainActivity to com.example.image_changer.Splash. But my application not launching com.example.image_changer.Splash activity.

I want com.example.image_changer.Splash as starting activity of my application.

I have tried these solutions:

1. In eclipse, I change this setting: Run menu-->Debug Configuration---->Under my app--->Android tab--->Launch Action---->Launch(radio button)---->select(from drop down menu)--->com.example.image_changer.Splash.



2. Internet search:

I have tried all solution given on this link: Change application's starting activity

In this link zeh (user) post comment, which is possibly look like same as my problem but nobody post better solution regarding this.

Note-When I run my program then it runs splash.java but not show on emulator screen, I know this because I code System.out.println(); in thread in splash.java and it print string every time in console when I run my app.

So how to solve this problem?

This is my manifest:

<uses-sdk
    android:minSdkVersion="14"
    android:targetSdkVersion="17" />

<application
    android:allowBackup="true"
    android:icon="@drawable/imagechanger"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.image_changer.Splash"
          >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name="com.example.image_changer.MainActivity1"></activity>
    <activity android:name="com.example.image_changer.GamesFragment"></activity>
    <activity android:name="com.example.image_changer.MoviesFragment"></activity>
    <activity android:name="com.example.image_changer.TabsPagerAdapter"></activity>
    <activity android:name="com.example.image_changer.TopRatedFragment"></activity>
    <activity android:name="com.example.image_changer.Imageswipe"></activity>
    <activity android:name="com.example.image_changer.Mapview"></activity>

    <activity
        android:name="com.example.image_changer.MainActivity"
        android:label="@string/app_name"></activity>


</application>

</manifest>

This is my Splash.java class file

package com.example.image_changer;

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

public class Splash extends Activity  {
/** Called when the activity is first created. */
 private Thread mSplashThread;    

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
      requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_splash);
        //setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); 

        final Splash sPlashScreen = this;   

        // The thread to wait for splash screen events
        mSplashThread =  new Thread(){
            @Override
            public void run(){
                try {
                    synchronized(this){
                        // Wait given period of time or exit on touch
                        wait(2500);

                    }
                }
                catch(InterruptedException ex){                    
                }



                // Run next activity

                Intent intent = new Intent();
                intent.setClass(sPlashScreen,MainActivity.class);
                System.out.println("your are in the intent");
                startActivity(intent);


                finish();
            }
        };

        mSplashThread.start();        
    }

    /**
     * Processes splash screen touch events
     */
    @Override
    public boolean onTouchEvent(MotionEvent evt)
    {
        if(evt.getAction() == MotionEvent.ACTION_DOWN)
        {
            synchronized(mSplashThread){
                mSplashThread.notifyAll();
            }
        }
        return true;
    }  
}
Community
  • 1
  • 1
Devendra Dagur
  • 840
  • 1
  • 14
  • 35

1 Answers1

0

Update your thread code to this.

new Handler().postDelayed(new Runnable() {
    public void run() {
                // Run next activity

                Intent intent = new Intent();
                intent.setClass(sPlashScreen,MainActivity.class);
                System.out.println("your are in the intent");
                startActivity(intent);


                finish();
       }
}, 2500);
Ahmad Raza
  • 2,850
  • 1
  • 21
  • 37
  • not working because I am not able to use handler as you post here `new Handler().postDelayed(new Runnable() {`, When I apply this in code eclipse give me an error `;` or `}` missing. – Devendra Dagur Mar 19 '14 at 12:03
  • answer updated, try now! let me know if you are still facing any compilation error. – Ahmad Raza Mar 19 '14 at 12:06
  • Ok, Brother Its working, But one more problem, I need to use this thread again on `public boolean onTouchEvent(MotionEvent evt)` method. So how to use this thread or handler in method. – Devendra Dagur Mar 19 '14 at 12:30
  • you can create handler object... and use handlerObject.postDelay(...) wherever you want. – Ahmad Raza Mar 19 '14 at 12:42