tiger February 2016

Exception on backpress fragment ..Searched but doesn't found any such

-I am having problem in fragment.. when i press back button or home button app crashes.. i search Google n stack overflow , but not applicable to mine.. can anyone suggest

 E/AndroidRuntime(2285): FATAL EXCEPTION: main
 E/AndroidRuntime(2285): Process: com.iaboh, PID: 2285
 E/AndroidRuntime(2285): java.lang.RuntimeException: Unable to pause activity {}: android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
 E/AndroidRuntime(2285):    at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3048)

Answers


Rohit5k2 February 2016

You are not calling startActivity using any activity context. You have two solutions.

Solution 1

Use activity context while calling startActivity()

Solution 2

Add this to your intent. Only if you want to launch an activity form a non activity context. Be careful with this flag. As per android documentation

When using this flag, if a task is already running for the activity you are now starting, then a new activity will not be started; instead, the current task will simply be brought to the front of the screen with the state it was last in.

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);


Shree Krishna February 2016

The error is clearly saying to add FLAG_ACTIVITY_NEW_TASK, Please consider the error.

Intent i = new Intent(this, YourActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);


Arpit Patel February 2016

You need to call first

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

That means all previous activity are clear Then call the new activity

startActivity(intent)

Post Status

Asked in February 2016
Viewed 2,673 times
Voted 11
Answered 3 times

Search




Leave an answer