Note that there are some explanatory texts on larger screens.

plurals
  1. POSplash Screen Causes MenuItems not to appear
    primarykey
    data
    text
    <p>I've built a splash screen that loads a (splash) activity and then starts another activity and it works fine. (I've attached it below - it's called SPLASH 1) </p> <p>I created another splash screen to replace this one which is supposed to only run once - then after creating a <code>SharedPreferences</code> boolean it is supposed to load another activity. Everything seems fine with this but now when it loads the new activity, none of the menuitems appear. I have no idea what changed in SPLASH 2 - but something in there is causing the <code>MenuItems</code> not to appear after it loads the exact same activity SPLASH 1 does (NEWCORE.JAVA)</p> <p>I'm really not sure what is going on here - any help is greatly appreciated!</p> <p>(please let me know if any additional info is needed)</p> <p>SPLASH 1. (WORKING)</p> <pre><code>import android.app.Activity; import android.os.Bundle; import android.os.Handler; import android.content.Intent; import com.nfc.linkingmanager.R; public class SplashScreen extends Activity { private boolean mIsBackButtonPressed; private static final int SPLASH_DURATION = 1000; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.splash_screen); Handler handler = new Handler(); // run a thread after 2 seconds to start the home screen handler.postDelayed(new Runnable() { @Override public void run() { // make sure we close the splash screen so the user won't come back when it presses back key finish(); if (!mIsBackButtonPressed) { // start the home screen if the back button wasn't pressed already Intent intent = new Intent(SplashScreen.this, NewCore.class); SplashScreen.this.startActivity(intent); } } }, SPLASH_DURATION); // time in milliseconds (1 second = 1000 milliseconds) until the run() method will be called } @Override public void onBackPressed() { // set the flag to true so the next activity won't start up mIsBackButtonPressed = true; super.onBackPressed(); } } </code></pre> <p>SPLASH 2 (NOT WORKING - CAUSES MENUITEMS not to appear on the activity it loads)</p> <pre><code>import android.app.Activity; import android.os.Bundle; import android.os.Handler; import android.content.Intent; import com.nfc.linkingmanager.R; import android.content.SharedPreferences; import java.lang.Object; import android.preference.PreferenceManager; public class SplashScreen extends Activity { private Handler handler = new Handler() { public void handleMessage(Message msg) { Intent i = new Intent(SplashScreen.this, AppActivity.class); SplashScreen.this.startActivity(i); this.finish(); } }; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); if(!prefs.getBoolean("first_time", false)) { SharedPreferences.Editor editor = prefs.edit(); editor.putBoolean("first_time", true); editor.commit(); Intent i = new Intent(SplashScreen.this, NewCore.class); this.startActivity(i); this.finish(); } else { this.setContentView(R.layout.country_list); handler.sendEmptyMessageDelayed(0, 2000); } } } </code></pre> <p>NEWCORE.JAVA (Connected to by both Splash Screens - Only missing MenuItems when using SPLASH 2)</p> <pre><code>import android.os.AsyncTask; import android.os.Bundle; import android.app.ListActivity; import android.content.Intent; import android.database.Cursor; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; import android.widget.CursorAdapter; import android.widget.ListView; import android.widget.SimpleCursorAdapter; import android.widget.AdapterView.OnItemClickListener; public class NewCore extends ListActivity { public static final String ROW_ID = "row_id"; private ListView conListView; private CursorAdapter conAdapter; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); conListView=getListView(); conListView.setOnItemClickListener(viewConListener); // map each name to a TextView String[] from = new String[] { "name" }; int[] to = new int[] { R.id.countryTextView }; conAdapter = new SimpleCursorAdapter(NewCore.this, R.layout.country_list, null, from, to); setListAdapter(conAdapter); // set adapter } @Override protected void onResume() { super.onResume(); new GetContacts().execute((Object[]) null); } @Override protected void onStop() { Cursor cursor = conAdapter.getCursor(); if (cursor != null) cursor.deactivate(); conAdapter.changeCursor(null); super.onStop(); } private class GetContacts extends AsyncTask&lt;Object, Object, Cursor&gt; { DatabaseConnector dbConnector = new DatabaseConnector(NewCore.this); @Override protected Cursor doInBackground(Object... params) { dbConnector.open(); return dbConnector.getAllContacts(); } @Override protected void onPostExecute(Cursor result) { conAdapter.changeCursor(result); // set the adapter's Cursor dbConnector.close(); } } @Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.country_menu, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { Intent addContact = new Intent(NewCore.this, NewCore.class); startActivity(addContact); return super.onOptionsItemSelected(item); } OnItemClickListener viewConListener = new OnItemClickListener() { public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1, int arg2,long arg3) { Intent viewCon = new Intent(NewCore.this, NewCore.class); viewCon.putExtra(ROW_ID, arg3); startActivity(viewCon); } }; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload