Im playing with a lockscreen and selcted my second activity as home launcher now.
So the home key is locked on lockscreen.
How do i start now the nova launcher (or another custom launcher) instead of my empty layout from second activity when I press the home key outside from lockscreen?
I'm a bit confused on this topic.
EDIT:
I have currently that configurations for my lockscreen activity in my manifest:
<activity
android:name=".LockscreenActivity"
android:excludeFromRecents="true"
android:screenOrientation="portrait"
android:launchMode="singleInstance"
android:clearTaskOnLaunch="true"
android:label="Lockscreen"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<!-- The following two intent-filters are the key to set homescreen -->
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Any i found out that i can use the onNewIntent. But it dont work :/
#Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
Log.e("debug", "actions: " + intent.getAction());
if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Log.e("debug", "ACTION MAIN");
Intent i = getPackageManager().getLaunchIntentForPackage("com.teslacoilsw.launcher");
startActivity(i);
}
}
Every time the lockscreenactivity will open when i press the home button.
Related
When app which lanchmode is singleTask was cold started by deeplink,I did something in the onCreate of "MainActivity" with the "ACTION_VIEW" intent.Then I pressed Home button so that app entered background. Then I changed location permision of my app in settings to kill app by system. Then I tap the app icon in the desktop,my app started.But the action and data of the new intent I got by calling method getIntent() in "onCreate" was as same as the intent that I got lastTime.The action of the two intents is both "action.View".
MainActivity int mainifest.xml below
<activity
android:name=".MainActivity"
android:screenOrientation="landscape"
android:exported="true"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="myScheme" />
</intent-filter>
</activity>
onCreate method below
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.e("onCreate", getIntent().getAction() + " " + getIntent().getDataString() + " ");
}
My problem is that why this problem happens, it seems android cached the intent.
I tried to call setIntent(new Intent()) to clear the itent,but it does'nt work for me.
Does anyone know how to solve this? Thks a lot.
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();
};
I've written a custom Launcher and it works pretty nice. The Launcher has some pages filled with applications. I want to implement, that the variable that represents the page number is set to 0, if the homebutton is pressed. So if you are on a different page of the launcher and press the homebutton, you enter the starting page.
I've searched a lot, but couldn't find an answer that worked for me.
I've set the app as an launcher in the manifest.
<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.LAUNCHER" />
</intent-filter>
Is it possible to achieve this? Just change the value of one variable, if the home button is pressed and leave the rest of the home button, as it is.
For everybody who want to do the same thing. that's the way i solved it:
I added the following to the manifest:
<activity
android:launchMode="singleTask"
android:clearTaskOnLaunch="true"
android:stateNotNeeded="true">
and wrote this into the java activity:
#Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
if (Intent.ACTION_MAIN.equals(intent.getAction())) {
final boolean alreadyOnHome =
((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
!= Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
if (alreadyOnHome) {
Log.d("whatever", "Home pressed");
}
}
}
I got it from here: CyanogenMod trebuchet
I am making a children's app and I would like to add a child lock to it, just like the one on the app called "Toddler lock". Toddler lock asks you to set the default launcher when the lock is turned on which allows the home button to be disabled.
How would I do this?
Ok so ive got a rough working example here:
Create two activities and two layouts, in the main layout place a normal button. The other layout can just have a blank <LinearLayout>.
This is what my manifest looks like:
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".secondact"
android:label="#string/secondtitle">
<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>
Notice <category android:name="android.intent.category.HOME" /> in second activity.
Here is the code from my main activity:
#Override
public void onResume()
{
super.onResume();
Button btn = (Button)findViewById(R.id.startBtn);
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent startMain = new Intent(Intent.ACTION_MAIN, null);
startMain.addCategory(Intent.CATEGORY_HOME);
startActivity(startMain);
}
});
}
And in my second activity i have:
#Override
public void startActivity(Intent intent)
{
super.startActivity(intent);
}
When i click the startbtn i get the dialog that you are talking about and you get to chooose launcher or the secondactivity, and select always use. The back button still gets you home, but hopefully this helps. This question might help you further: Disable home button in android toddler app?
I have an application that has one service and 2 activities.One activity (the main one) is a preferences activity and the other one is a dialog themed activity. The service from time to time needs to open only the dialog themed activity (using FLAG_ACTIVITY_NEW_TASK).
The problem is that when the preferences activity is opened in background (for example the user pressed HOME key instead of BACK, so the activity is OnPause) and the service tries to open the dialog themed activity, also the main activity is opened (comes in foreground).
I don't want this. So, how can I open only the themed activity from the service, without the main activity pop up ?
Android Manifest .xml
<service android:name=".SimpleService"> </service>
<activity
android:name=".Preferences" 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=".popup_activity" android:theme="#android:style/Theme.Dialog" android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.SAMPLE_CODE" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="screenon.popup.activity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
And from the service :
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.addCategory("screenon.popup.activity");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
I believe you're looking for the android:launchMode attribute.
Alex , I believe that all you want is to display preferences activity just once & then it must die(or lets say finish()) .
In that case you can override onResume of the preferences activity
to finish your preferences activity after it is resumed after pause
#Override
public void onResume()
{
//if activity is resumed after onPause then only run it
this.finish(); //simply kill your activity if it is resumed after pause
}
EDIT-To know whether the activity was paused you need to override onPause().I think you can dig out the rest.
Hope it helps!