0

I'm trying to block/disable the recent apps button in Android. To this end, I've tried to use this answer: Block/disable recent apps button

However, it seems not to work. I'm testing in on a emulated device for API 15. Is that answer right for API15+?

May I be missing something?

My application has two activities and I want it to be disabled for the second one so I have included the overridden onPause code to the second activity.

Thanks in advance

EDIT: This is question is not philosophical, it's about to have it working. I'm not new in Android and I know that what I want to do is against the common way to do the things in Android. I'm totally concious about it. This question is about to have something that others have made working and to know why it is not working .

EDIT2: It does not seem to be too much consistent the criteria if here you are marking this question negatively whereas the referred thread is positively marked being almost the same topic.

EDIT3: Manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.sample"
          android:versionCode="1"
          android:versionName="1.0">
    <uses-sdk android:minSdkVersion="15"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.REORDER_TASKS" />
    <application android:label="@string/app_name" android:icon="@drawable/ic_launcher">
        <activity android:name=".InitPage"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <activity android:name=".MainPage"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
                <category android:name="android.intent.category.HOME" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    </application>
</manifest>
Community
  • 1
  • 1
jevora
  • 469
  • 1
  • 5
  • 14
  • fortunately you cannot disable any hardware buttons – pskink Mar 15 '16 at 10:32
  • I need to do this as it will be an app that will be deployed in public infrastructures and people will be using it. Then, I don't want people to get out of the application. I want to allow an unique way to get out of the application which will be known by the admin of the devices – jevora Mar 15 '16 at 10:54
  • imagine an app that disables both back and home buttons, would you like to use it? i wouldn't, if you want such app write your own home launcher – pskink Mar 15 '16 at 10:57
  • Yes, I'm doing it as a launcher and I have back and home buttons disabled, but I don't manage to get working what was answered in the referred thread for the recent apps button – jevora Mar 15 '16 at 11:10
  • so what does your manifest look like? – pskink Mar 15 '16 at 11:27
  • check edit 3 in the post. Thanks – jevora Mar 15 '16 at 12:08
  • no need for in InitPage activity, what do you need `REORDER_TASKS` for? – pskink Mar 15 '16 at 12:14
  • It's supposed necessary according to the referred thread. Without it the code on method onPause would not work (another supposition) – jevora Mar 15 '16 at 16:55
  • if your app is a launcher so what other apps will be shown in the "recent tasks window" (your app is the only one)? honestly i dont see what is your problem then – pskink Mar 15 '16 at 17:11
  • Imagine the typical device of a tourism office in which people can see the tourist attractions of the city. Then, if this app is offered in a tablets that everyone can check in that office, it is desirable that no one can get out of the app (neither by back nor home nor recent apps). My idea is to allow a pattern to unblock so that someone knowing the pattern can get out of my app (but this will be only known by the workers of the office). I hope this gives you a better idea of why I want this. However I just wonder why the solution of the referred thread is not working in my case. – jevora Mar 15 '16 at 21:38
  • write your own launcher then: no other app can be launched from it (besides the "normal" launcher when unblocked by a pattern) – pskink Mar 15 '16 at 21:51
  • Yes, I have it like this. But the problem is that, when it's clicked, it gets like this [image](http://forums.androidcentral.com/attachments/google-nexus-7-tablet-2013/110967d1396650197t-nexus-7-apps-running-but-i-got-no-recent-apps-screen-nra.jpg). I want like in the referred thread in which it is hidden automatically. – jevora Mar 16 '16 at 10:01
  • why do you want to fight with "recent app window"? you cannot help it, just dont allow new apps to be added to that list – pskink Mar 16 '16 at 10:05
  • I understand your point, it's a minor detail and it won't allow to get out of my app. But, however, if, according to the other thread, the appearance of the recent apps window can be automatically hidden, I would prefer to have this behavior rather than keep it. Anyway, thanks for your effort in helping me. I really appreciate it. However, I hope there is someone who may know why this is not working in my app whereas other people confirm it works. – jevora Mar 16 '16 at 10:26
  • this is the same thing like using window manager in the service: people were trying multiple different options/flags to fool the google team and the google team was adding patches again and again to hide those security holes, the same here: someone found a workaround for something what was not intended to work and google fixed that in a new release – pskink Mar 16 '16 at 10:39
  • I see, that sounds logical. Well, then I can let it like it is now. Thanks! – jevora Mar 16 '16 at 11:22

2 Answers2

2

I've updated the SDK from API15 to API19 and this works.

Nimantha
  • 6,405
  • 6
  • 28
  • 69
jevora
  • 469
  • 1
  • 5
  • 14
0

Finally I found to achieve this by following:

@Override
protected void onPause() {
super.onPause();

ActivityManager activityManager = (ActivityManager) 
getApplicationContext()
    .getSystemService(Context.ACTIVITY_SERVICE);

activityManager.moveTaskToFront(getTaskId(), 0);
}

will need permission ...

<uses-permission android:name="android.permission.REORDER_TASKS" />
M. Diana
  • 11
  • 3