I'm creating a lock screen app and I have a problem:
If I use these intent filters in my lock activity:
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME"/>
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
so that I can handle home button press but the problem will be that when I reboot my phone/emulator my activity will run instantly(before on boot completed) and as home activity(I guess) and it won't proceed further and even after I unlock it by entering password(and call finish()) the activity launches again.
Any idea how should I solve this?
EDIT:
I thought of another way and that is to add intentFilters in run time this way I can avoid this problem but I don't know how to do it on activity and is it even possible?
P.S. I have searched for this a lot(more than one week constantly browsing stackoverflow) and many has suggested not to block home button but I need to so please help me.
Related
I have a launcher app which has a singleTask activity as the main entry point. When the user navigates away to another activity or to a 3rd party app and then hits the home button, then this activity should be brought to the front. However what I experience is that for the first home button press only, another instance is created instead (a new task is created, onCreate() is called). In the meantime the old task is still alive, containing the original instance of this activity, but it is impossible to navigate back to that task/activity or to bring it to the foreground.
After the first home button press, the next home button press brings the 2nd instance of this activity to the foreground. Not sure why not the very first instance's onNewIntent() method is called for the first time... So this only happens once, after that always the 2nd instance's onNewIntent() method is called. This means that the original activity will be not accessible..
I tried to bring the task to the foreground, nothing was happening... Like if it never existed (but the task is there with the activity, it is not killed at any point). I can find the task from code and also using a shell script. It contains the original activity
This is happening on Android TV (Os: Pie). Any idea what can be the reason for this? I do not really understand how this is happening... BTW the result is the same if I set the activity to singleInstance.
The activity looks like this:
<activity
android:name=".activities.MainActivity"
android:excludeFromRecents="true"
android:launchMode="singleTask"
android:theme="#style/AppTheme">
<intent-filter android:priority="2">
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.HOME"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.LEANBACK_LAUNCHER"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.ALL_APPS"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
I tried alternating the above attributes (priority, excludeFromRecents, taskAffinity), also removed them completely, they had no effect...
The home button press sends the following intent:
action: "android.intent.action.MAIN"
category:
"android.intent.category.HOME"
component: the above activity
it has also some extras but I do not think it is relevant
You are experiencing this nasty long-standing Android bug:
Re-launch of Activity on Home button, but...only the first time
You say in a comment that it doesn't happen with real users. That is not actually true. If a real user would install your app from the Play store and then launch it immediately (click the OPEN APP button after installation) then the problem would be reproduced exactly as you describe it.
I was struggling with the exactly same issue for the last couple of hours and I've read many similar Q&A about this topic/bug on StackOverflow. No solution really worked for me until, out of mere curiosity, I did the following.
If you're building a launcher and using onNewIntent() in your MainActivity (although OP doesn't mention that he's using this method), then simply comment out this line:
super.onNewIntent(intent);
Uninstall your app and install it again.
I don't know how this works, but EVEN when you then uncomment the very same line, it still behaves in a proper manner, that is: the app has really only single instance of its main activity all the time. And how I know that? My MainActivity is doing some database operations, and previously I saw in my Logcat that these operations were done twice every time, but now they are done only once.
And BTW my MainActivity tag in AndroidManifest.xml is nothing special:
<activity
android:name=".activities.MainActivity"
android:exported="true"
android:excludeFromRecents="true"
android:launchMode="singleTask">
<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>
i have tried different approaches to disable hardware home button through key-guard and key-down. it didn't work, i want functionality like Go-locker app. when i press on home button activity didn't close. please give me any idea about it. Thanks in advance.
Write this Intent filter in manifest in tag of your activity
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Because the security reason, if any app can disable Home button, and also disables back button (onbackpress()), power button (by on/off receiver), so the app will never be killed, and your phone just shows the app. I think Go-locker has customed their laucher, you can do it, but i think it is not easy.
Regards !
I have already finished an Android lock-screen app but my teacher asks me to change it into an app using Windowmanager so that users can not exit the app using HOME button. The idea is that we can make the whole app be a float full-screen window. But I don't know how to change a finished activity into a float window.
You just can't override the HOME button (or "make the HOME button unwork").
There was a time, about in Android 1.6 when you could do that, against Google's wishes. But now you just can't.
Think about it. If you could do that, some app you downloaded from the PlayStore could do that and render your phone unusable.
The closest you can get is adding CATEGORY_HOME as an intent of one of your activities. That way when the user touches the HOME button, he will be presented with the option to choose which activity will open when they touch HOME.
Here you've got an example on how to do it (you don't have to change anything in the Activity classs):
<activity
android:name="com.mpascual.example.HomeActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME"/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
This line is the relevant one (everything else is just an example):
<category android:name="android.intent.category.HOME"/>
So I have such tricky thing declared in Manifest to be able to start my app from a browser:
<activity android:name=".BrowserIntentCallBackActivity"
android:noHistory="true" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="*"
android:scheme="trickyapp" />
</intent-filter>
</activity>
this workds ok and starts my BrowserIntentCallBackActivity as expected. If my app wasnt previously started then finishing the BrowserIntentCallBackActivity returns user back to browser and its fine.
However if my app was previuosly started and is running on background finishing the BrowserIntentCallBackActivity returns user to previuos activity of my app. But I want to send user back to browser where he/she clicked the very special link and from where my BrowserIntentCallBackActivity was launched by intent. And I dont want ot kill my running app.
How to achieve this?
Try setting the launch mode of your activity:
https://developer.android.com/guide/topics/manifest/activity-element.html#lmode
I believe the correct mode for your task will be "singleTask" or maybe "singleInstance", although I have limited experience with those so you will have to experiment to be sure.
My app consists of 2 activities:
<activity
android:name="com.domain.android.MainActivity"
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="com.domain.android.AboutActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
I open my app, navigate to second screen, then go to the homescreen. From there I launch the app again - and it starts the main activity. But the app is running, it is just in the background, but why it didn't open the second activity? I guess it is something connected with activity's category. But how to fix that? Thanks.
Welcome to the ever-growing list of developers who have been bitten by this Android bug. Please see Re-launch of Activity on Home button, but...only the first time for all the gory details. And please go to Google Code and star the issues. We need all the noise we can make to get these fixed.
Hold your home button it will show the running apps click on your app it will open the activity from where you left. even if you click on the application launcher it will open the activity from where you left.
your application will not be in the same state sometimes if android needs resources it might end that activity. open an application move to next screen and press the home button and launch again it will open from where you left do the same with 5 or 6 apps then try launching the 1st app it will not be in the same state it will launch from the launch activity but any app you come to home screen and launch immediately it will open from where you left. If the background app is not doing anything android might end it if it needs resource. correct me if i am wrong. additional information i will be happy to know.
One issue may be that you have 2 activities designated as the main activity using:
<action android:name="android.intent.action.MAIN" />
You will probably have two icons in your launcher for your app. Each one will launch a different activity. You might be launching the first one again and again by using the icon for the first activity. Try removing
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
from your AboutActivity activity declaration. This might fix your problem.