0

This is my app I need to set a music(background) for this application

my MAIN ACTIVITY

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Thread Timer =new Thread( ){
            public void run(){
                try{
                    sleep(1000);
                    startActivity(new Intent("com.example.SPLASH"));

                }
                catch(InterruptedException e){
                    e.printStackTrace();
                }
                finally{
                    finish();
                }
            }
        };
        Timer.start();

    }




}

My Second activity

public class Splash extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);
    LinearLayout bt = (LinearLayout) findViewById(R.id.linear);
     bt.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
        Intent intent = new Intent(Splash.this, third.class);
        startActivity(intent);

        Toast.makeText(getApplicationContext(), "PINNI", Toast.LENGTH_SHORT).show();
        }
    });
    }


}
ilse2005
  • 11,189
  • 5
  • 51
  • 75
  • Why are you still using Eclipse for Android? – OneCricketeer Mar 02 '16 at 20:30
  • Really? I find Eclipse to be slower than Android Studio... – OneCricketeer Mar 02 '16 at 20:33
  • Thanks for your response @cricket_007 but i'm not looking for that. what exact i'm looking is when you open your app music also play automatically. i hope you understand my problem. – Mahesh Babu Mar 02 '16 at 20:35
  • I do understand the problem, and you need to "play an audio file" from `onCreate` in the Activity. – OneCricketeer Mar 02 '16 at 20:46
  • when you open games app how the music is playing.. that exactly i need – Mahesh Babu Mar 02 '16 at 21:45
  • Did you read the link I posted? You need an mp3 file and you open it and play it with the MediaPlayer class. None of the code you provided here attempts to do that, so I don't know what you want other than to simply play an audio file. – OneCricketeer Mar 02 '16 at 22:00
  • Dude i think u didn't understand my issue. i dont want to retrieve music from my sd card. i want to give a default audio file to my app. my issue is i have 3 images. i created splash screen when i open my app automatically the audio file has to play background. do you know temple run or candy crash games when you the game the default music is running by the same way. i need to put a some music – Mahesh Babu Mar 02 '16 at 22:44
  • "i want to give a default audio file to my app" ... In order to do that, you **need an mp3 file** – OneCricketeer Mar 02 '16 at 22:49
  • This topic is still a duplicate, such as [Preferred way to add background music to Android game?](http://stackoverflow.com/questions/11591447/preferred-way-to-add-background-music-to-android-game) and [Play background music in all activities of Android app](http://stackoverflow.com/questions/27579765/play-background-music-in-all-activities-of-android-app) – OneCricketeer Mar 02 '16 at 22:53
  • Thank you so much. it works for me. The only thing is audio is not stooping. – Mahesh Babu Mar 03 '16 at 00:06

0 Answers0