Karan_8 0 Newbie Poster

I am beginner in android programming, I am making a music app the problem I am facing with my app is when my app is minimized and I try to resume the app from the launch icon, splash screen appears for the specified time but after that the android home screen appears and when I try to open it again same thing happens, to start the app again I have to force stop the app.

what I am doing in the main activity is to find if device has an internet connectivity the app will stream on-line music but if there is no internet connectivity the app will play downloaded music.

main activity code is given below:

 public class MainActivity extends Activity {

    // flag for Internet connection status
    Boolean isInternetPresent = false;
    Boolean responseCode = false;

    // Connection detector class
    ConnectionDetector cd;

    int code;

    int splashtime=6000;
    Thread splash,t;
    ProgressBar pb1;
    Handler hd;

    SharedPreferences appPreferences;
    boolean isAppInstalled = false;

    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    appPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    isAppInstalled = appPreferences.getBoolean("isAppInstalled",false);
    if(isAppInstalled==false){
        /**
        create short code
        */

        Intent shortcutIntent = new Intent(getApplicationContext(),MainActivity.class);
        shortcutIntent.setAction(Intent.ACTION_MAIN);
        Intent intent = new Intent();
        intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
        intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getResources().getString(R.string.app_name));
        intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.drawable.icon));
        intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
        getApplicationContext().sendBroadcast(intent);
        /**
        Make preference true
        */
        SharedPreferences.Editor editor = appPreferences.edit();
        editor.putBoolean("isAppInstalled", true);
        editor.commit();
    }

    setContentView(R.layout.activity_main);

    // creating connection detector class instance
    cd = new ConnectionDetector(getApplicationContext());

    /**
    Check Internet status button click event
    */

    // get Internet status
    isInternetPresent = cd.isConnectingToInternet();

    if (isInternetPresent) {
        // Internet Connection is Present
        // make HTTP requests
    } 
    else {
        // Internet connection is not present
        // Ask user to connect to Internet
        Toast.makeText(getApplicationContext(), "You don't have internet connection.\n Opening Offline Player...", Toast.LENGTH_LONG).show();
    }

    pb1=(ProgressBar)findViewById(R.id.progressBar1);
    hd=new Handler();
    splash=new Thread(new Runnable(){

    @Override 
    public void run() {
        // TODO Auto-generated method stub
        //pb1.setVisibility(View.VISIBLE);
        synchronized(this)
        {
            try {
                    wait(splashtime);
            } 
                catch (InterruptedException e) {
                          // TODO Auto-generated catch block
                          e.printStackTrace();
                }

            finally{

               finish();

               // check for Internet status
               if (isInternetPresent) {
                    // Internet Connection is Present
                    // make HTTP requests
                    Intent i=new Intent();
                    i.setClass(MainActivity.this, MusicPlayerActivity.class);
                    startActivity(i);
                } 
                else {
                    // Internet connection is not present
                    // Ask user to connect to Internet
                    // Offline Palyer
                    Intent i = new Intent(getApplicationContext(), OfflineMusicPlayer.class);
                    startActivityForResult(i, 100);
                }


            }
        }
    }});

    splash.start();
    }

    }  

app works fine and when minimized the app can be accessed from recent apps button but it can't be resumed from the launch icon.

please help.