I want to intercept home button click of Android device in lollipop version.
I think this can be done in another style if suits your requirement. By
creating your activity as home activity. If you want to disable home button
and show your custom application activity as launcher when home button is
pressed. Just add these lines in manifest for that activity for which you want your launcher.
<activity
android:name="com.example.TempActivity"
android:clearTaskOnLaunch="true"
android:excludeFromRecents="true"
android:launchMode="singleTask"
android:screenOrientation="landscape"
android:stateNotNeeded="true" >
<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>
</activity>
if user presses the home button, Android will ask for which launcher you want your home. Then your have to select your application launcher ALWAYS not ONLY ONCE.
if you want fully disable the user, so that he cant move to another screen
then set theme to fullscreen with NoTilebar.
Use this method:
#Override
public void onAttachedToWindow() {
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
super.onAttachedToWindow();
};
Related
when i'm on the MainActivity in my app then press the setting menu in the action bar a new fragment is opened..there are two problems here
1- when i'm on the setting fragment then i press the multi-tasking button i found two windows for my app not one..the MainActivity and the settings
2- if i press the setting window when i'm still on multi-tasking window then press the back button it should take me to MainActivity instead it closes the app.
So now what i want to do is
1- close the MainActivity from the background once i open settings
2- if i press multi-tasking button and choose settings window in my app then press back it takes me to the MainActivity not close the whole app.
here is how i defined my activities in manifest file
<activity android:name=".MainActivity"
android:launchMode="singleInstance"
android:screenOrientation="portrait"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Settings"
android:label="#string/settings_title"
android:excludeFromRecents="true">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.android.bee.MainActivity"/>
</activity>
<receiver android:name=".Notifications"/>
</application>
hope the image helps visualizing it..thanks alot
Remove the android:launchMode="singleInstance" attribute.
I am working on a launcher application. It is being show along with the default launcher on pressing the back button. However, wherever I am in my custom launcher or whether in the starting page of my launcher it self, when I press the back button, the screen navigates back to the default android launcher. I need help.
This is the code I used to set my app as a launcher
<intent-filter>
<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.MONKEY" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
thank you in advance
This seemed to work for me
Kotlin
override fun onBackPressed() {}
Java
#Override
public void onBackPressed() {}
Those are categories for intents, android.intent.category.LAUNCHER just means when you run the application it will launch the specified class
So I have an Activity A that is defined in the AndroidManifest.xml as defined below:
<activity
android:name=".activity.A"
android:screenOrientation="landscape"
android:windowSoftInputMode="stateAlwaysHidden"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
This Activity launches a welcome Screen which we will call Activity B.
If you launch the application the Welcome screen is displayed and then once the user is done with it Activity A comes back.
The issue I am having is when I push the "Home" button from the welcome screen I go back to the Home Screen as expected. Now when I reclick on the Application Icon the application won't launch. Instead both my Activity A & B get destroyed. If I click on the icon again then the application relaunches as expected.
Now if I'm on the welcome screen and push the back arrow and reclick on the App icon it launches the application as expected. I don't have to push it twice.
Unfortunately I have to use the launchMode="singleTask" since it is a requirement for integration with another team. I have read the Android API's for Tasks and Back Stacks numerous times. Any pointers or suggestions would be greatly appreciated.
I came across a blog indicating there is an undocumented bug with using singleTask and intent-filters together but didn't find any official documentation on this.
Thanks
EDIT
Launching Activity B like this:
Intent intent = new Intent(context, B.class);
startActivityForResult(intent, CONST_VAR);
I tried making two activities which launches ActivityB from Activity A. I see no such problem as described in the question. PFB my manifest. Also, when you say home button, is it Phone home button or your app specific home button. PFB my manifest
<activity
android:name="com.android.testsingletask.MainActivity"
android:launchMode="singleTask"
android:screenOrientation="landscape"
android:windowSoftInputMode="stateAlwaysHidden"
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.android.testsingletask.WelcomeActivity"
android:screenOrientation="landscape"
android:windowSoftInputMode="stateAlwaysHidden"
android:label="#string/app_name" >
</activity>
I am designing an Home Screen in which I am showing the applist in a gridview.
There are some animation in the 1st screen of my HOMESCREEN and when you press on a button then a grid is shown.
So, the problem is that;
1)).I opened an application from the gridview,it opens normally but when i exit from that particular application,the BACKButton takes me to the screen of GridView.(It is OKAY).
Now,When I press the HOME Button,It is doing the same work as it does on BACKBUTTON.
I am listening to these butons using dispatchKeyEvent(KeyEvent event) but it is not working with home button..
Logically ,I should not work because this dispatchKeyEvent(KeyEvent event) works for my application not for any other application..
I found some other paths to resolve this problem,
When i open other apps,onPause() and onStop() functions are called in my homescreen,suppose I set a flag over there but by doing this How will I be able to know that after doing his stuff in OTher application user presses HOME BUTTON or BACK BUTTON.
You should declare your home activity look like below code
<activity
android:name="com.android.launcher2.Launcher"
android:launchMode="singleTask"
android:clearTaskOnLaunch="true"
android:stateNotNeeded="true"
android:theme="#style/Theme"
android:windowSoftInputMode="stateUnspecified|adjustPan"
android:configChanges="locale">
<intent-filter>
<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.MONKEY"/>
</intent-filter>
</activity>
and declare gridactivity as a normal activity in Manifest
I hope you got solution.
dispatchKeyEvent(KeyEvent event) won't be able to catch Home button click. if you want to capture Home button click use onUserLeaveHint().
And to capture back button specifically use onBackPressed().
I'm building a home screen application for android and I'd like to disable (temporary) the default home screen (TwLauncher) or whatever app is running.
Is there any way to accomplish this?
You can't disable other homescreens, but you can register your app as a homescreen by adding the appropriate intent-filters to your manifest:
<activity android:name="Home"
android:theme="#style/Theme"
android:launchMode="singleInstance"
android:stateNotNeeded="true">
<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>
</activity>
Different homescreens can exists concurrently, the user ultimately decides which homescreen he wants to set as his default homescreen manually.
Please have a look to this sample code on the official website : Home app sample
I also encounter that problem here is the solution go to preferences of your default launcher look for exit for ex: exit go launcher ex then ok. This will disable the default.