0

currently I need to create an application of wallpaper. I need to start a splash screen before enter into main screen. my main screen is developed using reference from slidingmenu. However, after start splash screen, I have got error below: Please advise and help. Thank you !!

Error after start a fragment activity after run splash screen

    E/StrictMode: A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
   java.lang.Throwable: Explicit termination method 'end' not called
              at dalvik.system.CloseGuard.open(CloseGuard.java:184)
              at java.util.zip.Inflater.<init>(Inflater.java:82)
              at com.android.okio.GzipSource.<init>(GzipSource.java:57)

Splash Screen activity

public class SplashScreen extends SherlockActivity {
    // Splash screen timer
    private static int SPLASH_TIME_OUT = 2000;

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

    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 i = new Intent(SplashScreen.this, FragmentChangeActivity.class);
            startActivity(i);

            // close this activity
            finish();
        }
    }, SPLASH_TIME_OUT);
}

}

Fragment Activity

public class FragmentChangeActivity extends MainActivity {

    private Fragment mContent;

public FragmentChangeActivity() {
    super(R.string.changing_fragments);
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // set the Above View
    if (savedInstanceState != null)
        mContent = getSupportFragmentManager().getFragment(savedInstanceState, "mContent");
    if (mContent == null)
        mContent = new ColorFragment(R.color.red);

    // set the Above View
    setContentView(R.layout.content_frame);
    getSupportFragmentManager()
            .beginTransaction()
            .replace(R.id.content_frame, mContent)
            .commit();

    // set the Behind View
    setBehindContentView(R.layout.menu_frame);
    getSupportFragmentManager()
            .beginTransaction()
            .replace(R.id.menu_frame, new ColorMenuFragment())
            .commit();

    // customize the SlidingMenu
    getSlidingMenu().setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
}

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    getSupportFragmentManager().putFragment(outState, "mContent", mContent);
}

public void switchContent(Fragment fragment) {
    mContent = fragment;
    getSupportFragmentManager()
            .beginTransaction()
            .replace(R.id.content_frame, fragment)
            .commit();
    getSlidingMenu().showContent();
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.share:
            new AlertDialog.Builder(this)
                    .setTitle(R.string.share)
                    .setMessage(Html.fromHtml(getString(R.string.apache_license)))
                    .show();
            break;
        case R.id.info:
            new AlertDialog.Builder(this)
                    .setTitle(R.string.info)
                    .setMessage(Html.fromHtml(getString(R.string.about_msg)))
                    .show();
            break;
    }
    return super.onOptionsItemSelected(item);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getSupportMenuInflater().inflate(R.menu.example_list, menu);
    return true;
}
}
michelletbs
  • 809
  • 2
  • 9
  • 19

2 Answers2

0

Remove the

public MainActivity(int titleRes) {
    mTitleRes = titleRes;
}

Activity classes are instantiated with the no-arg constructor and your activity does not have it. Declaring an explicit constructor prevents the implicit no-arg constructor from being generated.

To pass parameters to activities, use the extras Bundle with the Intent. Start an Activity with a parameter

Community
  • 1
  • 1
laalto
  • 150,114
  • 66
  • 286
  • 303
  • Thank you @laalto for helping. I have understand how to start an activity with a parameter now. Currently I want to start a fragment activity after splash screen. but it returns error above. I am new to Android and also library Jeremyfeinstein. Need your opinion. Thank you ! – michelletbs Jan 12 '16 at 01:02
0

I am able to display the splash screen now. Here is the code:

public class SplashScreen extends SherlockFragmentActivity {
    // Splash screen timer
    private static int SPLASH_TIME_OUT = 2000;
    private PictureFragment mainFragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Add the fragment on initial activity setup
        if (savedInstanceState == null) {
            // Add the fragment on initial activity setup
            mainFragment = new PictureFragment();
            getSupportFragmentManager()
                    .beginTransaction()
                    .add(android.R.id.content, mainFragment)
                    .commit();
        } else {
            // Or set the fragment from restored state info
            mainFragment = (PictureFragment) getSupportFragmentManager()
                    .findFragmentById(android.R.id.content);
        }

           }
}

Here is the code to display splash screen image

public class PictureFragment extends SherlockFragment {

// Splash screen timer
private static int SPLASH_TIME_OUT = 2000;


@Override
public View onCreateView(LayoutInflater inflater,
                         ViewGroup container,
                         Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.activity_splash, container, false);


    new Handler().postDelayed(new Runnable() {

        @Override
        public void run() {
            Intent i = new Intent(getActivity(), FragmentChangeActivity.class);
            startActivity(i);
            getActivity().finish();
        }
    }, SPLASH_TIME_OUT);
    return view;
}

}

michelletbs
  • 809
  • 2
  • 9
  • 19