I am trying to access if user is logged in or not, based on that I try to start activity for the application. While doing this, the app crashes in the Application class.
The code for application class is
public class MyClass extends Application {
public static Context context;
@Override
public void onCreate() {
super.onCreate();
context = getApplicationContext();
if(ParseUser.getCurrentUser().isAuthenticated()){
startActivity(new Intent(context, MainActivity.class));
}
}
}
Any suggestion why this happens ?
In my Manifest I have declared the intent filter for another activity.
<activity
android:name=".Activities.Register"
android:label="@string/title_activity_register" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Call the startActivity() method with the new intent as the argument. startActivity(intent); Run the app. When you click the Send button the main activity sends the intent and the Android system launches the second activity.
To start an activity, use the method startActivity(intent) . This method is defined on the Context object which Activity extends. The following code demonstrates how you can start another activity via an intent. # Start the activity connect to the # specified class Intent i = new Intent(this, ActivityTwo.
The flags you can use to modify the default behavior are: FLAG_ACTIVITY_NEW_TASK. Start the activity in a new task. If a task is already running for the activity you are now starting, that task is brought to the foreground with its last state restored and the activity receives the new intent in onNewIntent() .
public Context call mcontext;<br> // ..... <br> Intent intent = new Intent(call mcontext, AboutActivity. class);<br> call mcontext. startActivity(intent);
Intent intent = new Intent(context, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
Also if you look at Logcat in Android Studio, you should be seeing error log that has already told you how to fix this issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With