2

In my app when user press back the app is minimised. This is the onBackPressed() method

@Override
public void onBackPressed() {
    Intent i = new Intent();
    i.setAction(Intent.ACTION_MAIN);
    i.addCategory(Intent.CATEGORY_HOME);
    startActivity(i);
}

but it shows me this error I dont know how to resolve it. please help me with this.

This is the error log

java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.HOME] cmp=com.android.customlockapp/.CustomLockLauncher } from ProcessRecord{41490d70 456:itpp.anubhabmassretail/u0a100} (pid=456, uid=10100) not exported from uid 10061
   at android.os.Parcel.readException(Parcel.java:1425)
   at android.os.Parcel.readException(Parcel.java:1379)
   at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:1761)
   at android.app.Instrumentation.execStartActivity(Instrumentation.java:1411)
   at android.app.Activity.startActivityForResult(Activity.java:3351)
   at android.app.Activity.startActivityForResult(Activity.java:3312)
   at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:839)
   at android.app.Activity.startActivity(Activity.java:3522)
   at android.app.Activity.startActivity(Activity.java:3490)
   at itpp.anubhabmassretail.MainActivity.onBackPressed(MainActivity.java:87)
   at android.app.Activity.onKeyUp(Activity.java:2131)
   at android.view.KeyEvent.dispatch(KeyEvent.java:2633)
   at android.app.Activity.dispatchKeyEvent(Activity.java:2361)
   at android.support.v7.app.ActionBarActivityDelegateICS$WindowCallbackWrapper.dispatchKeyEvent(ActionBarActivityDelegateICS.java:258)
   at    com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1823)
   at android.view.ViewRootImpl.deliverKeyEventPostIme(ViewRootImpl.java:3600)
   at android.view.ViewRootImpl.handleImeFinishedEvent(ViewRootImpl.java:3570)
   at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:2809)
   at android.os.Handler.dispatchMessage(Handler.java:99)
   at android.os.Looper.loop(Looper.java:137)
   at android.app.ActivityThread.main(ActivityThread.java:4794)
   at java.lang.reflect.Method.invokeNative(Method.java)
   at java.lang.reflect.Method.invoke(Method.java:511)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
   at dalvik.system.NativeStart.main(NativeStart.java)
Biswajit
  • 1,829
  • 1
  • 18
  • 33
  • 1
    Can you explain why you are trying to launch the home screen app (but your logcat looks like the lock screen) and not following: http://developer.android.com/guide/components/tasks-and-back-stack.html for back stack behavior. – Morrison Chang Dec 31 '14 at 07:38
  • Because I want to minimise the app and show the homescreen, so I do that. Is there any other efficient way to do that? – Biswajit Dec 31 '14 at 07:40
  • Did you read the link? What happens when the user switches to your app from a different app and tried to go back. Where will the user go and does that follow Android navigation patterns: http://developer.android.com/design/patterns/navigation.html#between-apps – Morrison Chang Dec 31 '14 at 07:44
  • Yes bro you are right then is there any other way? What should I do when user press the back button? – Biswajit Dec 31 '14 at 07:57
  • 1
    Read the links. Take a look at this one: http://developer.android.com/training/implementing-navigation/temporal.html Figure out what back stack behavior makes sense for your app. Good luck. – Morrison Chang Dec 31 '14 at 08:08

2 Answers2

1

Add

android:exported="true"

to your activity's manifest.

(a bit long overdue answer but... still :D)

WindRider
  • 11,958
  • 6
  • 50
  • 57
0

In MainActivity.cs, I add 'Exported = true'

[Activity(WindowSoftInputMode = SoftInput.AdjustResize,
    HardwareAccelerated = true, ResizeableActivity = false,Exported = true)]
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 17 '23 at 07:09