-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[quick_actions] Implementing sharedpreferences approach for killed apps #1800
Changes from all commits
1f7adb1
a16b777
26d3929
eb1b0b1
32906ee
25cf85b
bc8ca5b
0cffd7b
48de23d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| ## 0.3.2 | ||
|
|
||
| * Fixed the quick actions launch on Android when the app is killed. | ||
|
|
||
| ## 0.3.1 | ||
|
|
||
| * Added unit tests. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,12 @@ | ||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
| package="io.flutter.plugins.quickactions"> | ||
| xmlns:tools="http://schemas.android.com/tools" | ||
| package="io.flutter.plugins.quickactions"> | ||
|
|
||
| <application> | ||
| <activity android:name=".QuickActionsPlugin$ShortcutHandlerActivity" android:exported="false"/> | ||
| </application> | ||
| <application> | ||
| <activity | ||
| android:name=".QuickActionsPlugin$ShortcutHandlerActivity" | ||
| android:exported="false" | ||
| android:relinquishTaskIdentity="true" | ||
| tools:targetApi="lollipop" /> | ||
| </application> | ||
| </manifest> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,8 @@ | |
| @SuppressWarnings("unchecked") | ||
| public class QuickActionsPlugin implements MethodCallHandler { | ||
| private final Registrar registrar; | ||
| private static final String intentExtraAction = "action"; | ||
| private static String launchAction = null; | ||
|
|
||
| // Channel is a static field because it needs to be accessible to the | ||
| // {@link ShortcutHandlerActivity} which has to be a static class with | ||
|
|
@@ -45,6 +47,7 @@ private QuickActionsPlugin(Registrar registrar) { | |
| public static void registerWith(Registrar registrar) { | ||
| channel = new MethodChannel(registrar.messenger(), "plugins.flutter.io/quick_actions"); | ||
| channel.setMethodCallHandler(new QuickActionsPlugin(registrar)); | ||
| launchAction = registrar.activity().getIntent().getStringExtra(intentExtraAction); | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -68,6 +71,10 @@ public void onMethodCall(MethodCall call, Result result) { | |
| case "clearShortcutItems": | ||
| shortcutManager.removeAllDynamicShortcuts(); | ||
| break; | ||
| case "getLaunchAction": | ||
| result.success(launchAction); | ||
| launchAction = null; | ||
| return; | ||
| default: | ||
| result.notImplemented(); | ||
| return; | ||
|
|
@@ -117,8 +124,27 @@ protected void onCreate(Bundle savedInstanceState) { | |
| String type = intent.getStringExtra("type"); | ||
| if (channel != null) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I ran your code and this channel check will make the opening fail when
Possible fix that is not a breaking change:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I know about this issue and it isn't something I wanted to fix in this PR. If you can, please, check the current version of the plugin and make sure that the bug was there before my fix. I don't know if I should fix it in this PR, maybe you can open an issue or even submit a PR? Or do you think that it's better to fix the bug in this PR? Anyway, I will check your solution, because I also faced this issue and was thinking about the ways to fix it.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @collinjackson ☝️ ? Another PR? It seems small enough to land together with this version.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @BugsBunnyBR I know why does this happen. When you click the "Back" button, the activity is being killed. So, the activity is killed now, but
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah. I know how to solve the problem. Just remove the static for the channel. In general, having static fields that are associated with context are a bad ideia. But removing the static makes that we need some other few changes, like listening to onNewIntent, that is why I think another pr will be needed to have a proper handling. |
||
| channel.invokeMethod("launch", type); | ||
| } else { | ||
| startActivity(getIntentToOpenMainActivity(this, type)); | ||
| } | ||
| finish(); | ||
| } | ||
|
|
||
| /** | ||
| * Returns Intent to launch the MainActivity. Used to start the app, if one of quick actions was | ||
| * called from the background. | ||
| */ | ||
| private Intent getIntentToOpenMainActivity(Context context, String type) { | ||
| Intent launchIntentForPackage = | ||
| context | ||
| .getPackageManager() | ||
| .getLaunchIntentForPackage(context.getApplicationContext().getPackageName()); | ||
| if (launchIntentForPackage == null) { | ||
| return null; | ||
| } else { | ||
| launchIntentForPackage.putExtra(intentExtraAction, type); | ||
| return launchIntentForPackage; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ description: Flutter plugin for creating shortcuts on home screen, also known as | |
| Quick Actions on iOS and App Shortcuts on Android. | ||
| author: Flutter Team <[email protected]> | ||
| homepage: https://github.com/flutter/plugins/tree/master/packages/quick_actions | ||
| version: 0.3.1 | ||
| version: 0.3.2 | ||
|
|
||
| flutter: | ||
| plugin: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just curious, what is this for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need
tools:targetApito hide a warning in android studio regardingandroid:relinquishTaskIdentity— the previous one. We can usetargetApi — lollipopas the plugin anyways works on devices from API at least 25. Also, in case, if the app is killed and we open it using the shortcut, it will work fine but only the first time. If you click the Home button after that and use the same shortcut again it will not work the second and following times withoutandroid:relinquishTaskIdentity.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you tried
android:noHistory="true"? Asandroid:relinquishTaskIdentity="true"works only on API +25, all users in APIs below that will not have the same behavior.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, exactly the same API version Android shortcuts and its classes were added ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh shortcuts are API 25+. So there is no problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will wait the merge to make another PR. I found that some more changes are needed. Sorry for the trouble.