David Kirwan
David Kirwan

Reputation: 75

Android onCreate not firing on new activity

Hi there I am trying to execute some code when I change to the next activity, but it does not seem to work. The Previous activity is a login page if the user is already logged in it goes straight to the new activity. But the onCreate does not seem to fire.

Main Activity

public class MainActivity extends AppCompatActivity {


    private View mMainView;
    private Meteor mMeteor;


    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        setTitle("ACTIVITY");
        Log.d("SimpleActivity","OnCreate Started");

        if(MeteorSingleton.getInstance().isConnected()){
            Log.d("Connection", "Connected");
        }else{
            Log.d("Connection", "Not Connected");
        }

        }

        ........

The strange thing is the setTitle works but none of the logs.

Here is some code from the previous login in page.

    @Override
    public void onConnect(boolean signedInAutomatically) {
        Log.i("Connection", "Connected to host server");
        if (mMeteor.isLoggedIn()) {
            openMainScreen(mLoginFormView);
        }
    }



     public void openMainScreen(View view) {
        Intent dashboard = new Intent(getApplicationContext(), MainActivity.class);
        startActivity(dashboard);
    }

Manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="system.carproject.adam.ams">

    <!-- To auto-complete the email text field in the login form with the user's emails -->
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.READ_PROFILE" />
    <uses-permission android:name="android.permission.READ_CONTACTS" />

    <!--
         The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
         Google Maps Android API v2, but you must specify either coarse or fine
         location permissions for the 'MyLocation' functionality. 
    -->
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".LoginActivity"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".MainActivity"
            android:label="Activity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="@string/google_maps_key" />

        <activity
            android:name=".MapsActivity"
            android:label="@string/title_activity_maps"></activity>

    </application>

</manifest>

If someone could educate me on this would be great. Can seem to figure it out.

Thanks

Upvotes: 0

Views: 851

Answers (2)

Chetan Joshi
Chetan Joshi

Reputation: 5711

You have created two LAUNCHER Activities and that's created two App Icon in your Device so if you think its open directly MainActvity then its possible if you click on second app icon in your device for same application . check your device .

first remove LAUNCHER mode from MainActvity in Android Manifest and then you have to add manual check in your login Activity onCreate() for login status and then startActvity() MainActivty if login status is true.

Upvotes: 1

Karan Kalsi
Karan Kalsi

Reputation: 819

try removing the intent filter tag from activity tag of MainActivity in Manifest:-

 <activity android:name=".MainActivity"
  android:label="Activity"> </activity>

Upvotes: 0

Related Questions