我正在自己更换家用发射器,并且工作正常,但有一件事困扰着我。当我按下Home键时,当前的Home活动(在清单中定义为main / defualt / launcher / home)将重新启动-当前活动实例onpause被执行,并且oncreate被再次触发,因此启动了新活动。
另一方面,ADW启动器和LauncherPRo的行为不一样-我的情况没有刷新。Launcher Pro甚至可以执行以下操作:
任何想法如何做到这一点?
我只是从头开始做了一个非常简单的原型,只有一个活动(在清单中定义为main / defualt / launcher / home),我看到的是同一件事-如果按Home键,它将重新创建。
可能重复:
Android:更改默认主页应用程序
我想创建一个像" Home Switcher "这样的程序,可以通过编程方式设置默认启动器.我还没有编写代码,但可以找出如何找到可用的启动器应用程序,但我不知道如何以编程方式设置默认值.谁能指出我正确的方向?
我有一个应用程序,我试图用它“进入 Kiosk 模式”,但是我只希望它只发生在一个 Activity 上。在修改了一些控件之后,我想出了Intent.createChooser().
我想要做的是一旦 ActivityonCreate()被调用,触发Intent.createChooser()以提示用户将其设置为默认的 Home 应用程序;这样,我“禁用”了主页按钮,因为在这种情况下,我已将启动活动编程为直接返回到我的信息亭活动。
一旦 Kiosk Activity 通过密码退出到前一个,我想createChooser()再次调用,以便用户可以将我的应用程序“取消设置”为默认的 Home 应用程序,他现在可以继续照常使用 Home 按钮。
问题是,当我打电话时createChooser(),“设置为默认应用程序”复选框没有出现。我如何让它出现?
这是我的调用代码createChooser():
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(Intent.createChooser(intent, "Set as default to enable Kiosk Mode"));
Run Code Online (Sandbox Code Playgroud)
我看过帖子说我应该使用startActivityForResult(),并且我尝试用startActivity()以下内容替换我的:
startActivityForResult(intent, 1);
Run Code Online (Sandbox Code Playgroud)
但这只是立即调用了我的默认应用程序,而没有弹出选择器屏幕。
当我们以给定的流程在Android设备中安装应用程序时,我发现任何Android应用程序都有一个非常奇怪的错误。
同样在STEP:4中,如果我选择“完成”选项,然后启动我的应用程序,则它工作正常。
它是与Android OS相关的错误吗?还是我做错了什么?
在这方面的任何建议都表示赞赏。
谢谢HImanshu
我有一个应用程序,如果从另一个应用程序启动(例如通过 Playstore),它会出现错误。它不会恢复到已经存在的实例Activity,而是作为新实例重新启动。
我拥有的:
launchMode="singleTop"声明每项活动manifest.xmllaunchMode=singleTask,但它具有相同的行为intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)在每个Intent开始新的内容时使用额外的ActivityonNewIntent()不在已经运行的实例中调用我使用以下代码从另一个应用程序启动我的应用程序(带或不带附加addFlag())
Intent launchIntent = getPackageManager().getLaunchIntentForPackage("my.package.name");
launchIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(launchIntent);
Run Code Online (Sandbox Code Playgroud)
我的启动器活动是一个SplashScreenActivity,如果MainActivity用户使用以下代码登录并获取finished()
Intent intent = null;
intent = new Intent(SplashScreenActivity.this, HomeActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
finish();
Run Code Online (Sandbox Code Playgroud)
我缺少什么?有什么建议欢迎留言!
我开发了一个作为启动器应用程序工作的应用程序。当用户从默认启动器中删除我的应用程序时,我需要知道它。
用户可以通过两种方式从默认启动器中删除我的应用程序:
1. Settings->Apps->Reset app preferences.
2. Settings->Apps->My_App->Clear default launcher.
如果有人有任何想法,请发表评论:
1. How I can detect my app is removed from the default launcher?
2. Is there any listener/action for it?
3. Is there any way by which I can restrict/block clearing default launcher?
提前致谢!
这是我用作按钮背景的“mydrawable”的 xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="false" android:state_pressed="false" >
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:angle="-45"
android:endColor="@color/colorPrimary700"
android:startColor="@color/colorPrimary600"
android:type="linear" />
<corners android:radius="@dimen/ic_button_corner"></corners>
</shape>
</item>
<item android:state_focused="false" android:state_pressed="true" >
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:angle="-45"
android:endColor="@color/colorPrimary800"
android:startColor="@color/colorPrimary700"
android:type="linear" />
<corners android:radius="@dimen/ic_button_corner"></corners>
</shape>
</item>
</selector>
Run Code Online (Sandbox Code Playgroud)
这是一个用例
<Button
android:id="@+id/login_button"
style="?android:textAppearanceSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/mydrawable"
android:text="@string/log_in"/>
Run Code Online (Sandbox Code Playgroud)
如何将此静态可绘制对象移植到具有可配置参数(例如每个项目的渐变中使用的颜色和大小角半径)的自定义视图中?
例如通过 Java
MyDrawable myDrawable=new MyDrawable();
myDrawable.setGradientColors(color1, color2);
myDrawable.setCornerRadius(size);
button.setBackground(Drawable);
Run Code Online (Sandbox Code Playgroud)
是否也可以通过自定义按钮(MyButton,而不是 MyDrawable)?
<MyButton
parameter_gradientcolor1:@color/color1
parameter_gradientcolor2:@color/color2
... />
Run Code Online (Sandbox Code Playgroud)
编辑
这是行不通的,既没有对点击事件的反应,也没有正确的渐变
public class SelectorButton extends AppCompatButton {
StateListDrawable mStateListDrawable;
public SelectorButton(Context context, …Run Code Online (Sandbox Code Playgroud) xml android android-custom-view android-launcher android-drawable
我有一个主要活动,其意图是 CATEGORY_HOME 表现得像一个启动器。它还具有 CATEGORY_LAUNCHER 以便用户可以从 App Drawer 访问。以下是主要活动:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
protected void onResume() {
super.onResume();
}
@Override
protected void onDestroy() {
super.onDestroy();
}
}
Run Code Online (Sandbox Code Playgroud)
我有另一个活动,其中包含一个按钮,可以使用 HOME 意图调用 MainActivity。它是 App Drawer 的另一个入口点。这是测试活动:
public class TestActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
findViewById(R.id.btn_test).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(TestActivity.this, MainActivity.class);
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
}); …Run Code Online (Sandbox Code Playgroud) 由于某些要求,我的启动器活动的 launchMode 属性设置为 singleTask。
<activity
android:name=".map.MapsActivity"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:theme="@style/MapScreenTheme"
android:windowSoftInputMode="adjustPan">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)
我面临的问题是,如果我打开另一个活动 -> 按主页 -> 单击启动器应用程序中的应用程序图标 -> 它会打开 MapActivity 而不是之前打开的活动。
但是,如果我通过最近菜单导航到该应用程序,则不会发生这种情况。然后新打开的活动保持在顶部。
有人可以解释一下这里发生的关于 backstack 的事情,为什么 ActivityManagerService 没有考虑到应用程序进程已经存在,但决定启动启动器应用程序并清除 backstack 而不是简单地将应用程序向前推进?
可以在此处创建的一个小示例应用程序中观察到此问题 - https://github.com/abhiank/SingleTaskActivity
我使用了 flutter 风味,但无法运行,但它使用此类命令从终端运行:
flutter run --flavor prod -t lib/main_prod.dart
Run Code Online (Sandbox Code Playgroud)
当我使用 android studio 运行按钮运行时,会显示此异常,我在下面写下:
异常:Gradle 构建无法生成 .apk 文件。该文件很可能是在 C:\Users\ranak\StudioProjects\bachelor_flat\build 下生成的,但该工具找不到它。
android-launcher ×10
android ×9
default ×2
block ×1
dart ×1
firebase ×1
flutter ×1
launcher ×1
launchmode ×1
xml ×1