Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I jump native(MainActivity) to flutter,but can not jump back. #12

Open
jinyulei0710 opened this issue Jan 1, 2019 · 7 comments
Open

Comments

@jinyulei0710
Copy link

01-01 09:45:55.374 14183-14183/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.greentownit.parkmanagement, PID: 14183
android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
at android.app.ContextImpl.startActivity(ContextImpl.java:734)
at android.app.ContextImpl.startActivity(ContextImpl.java:721)
at android.content.ContextWrapper.startActivity(ContextWrapper.java:345)
at com.taobao.hybridstackmanager.XURLRouter.openUrlWithQueryAndParams(XURLRouter.java:38)
at com.greentownit.parkmanagement.ui.MainActivity$1.onClick(MainActivity.java:39)
at android.view.View.performClick(View.java:5697)
at android.widget.TextView.performClick(TextView.java:10814)
at android.view.View$PerformClick.run(View.java:22526)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

@jinyulei0710
Copy link
Author

Samsung SM-G9350 Android 6.0,and when I add FLAG_ACTIVITY_NEW_TASK flag to intent,I jump native(MainActivity) to flutter,but can not jump back.

@jinyulei0710 jinyulei0710 changed the title android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want? I jump native(MainActivity) to flutter,but can not jump back. Jan 1, 2019
@kangwang1988
Copy link
Contributor

@jinyulei0710
If possible, please create a demo project (github) which may help me reproduce this problem.
Besides, paste result forflutter doctor -v here.

@jinyulei0710
Copy link
Author

@kangwang1988 here is the demo: https://github.com/jinyulei0710/hybridDemo.git
flutter doctor -v result:
[✓] Flutter (Channel master, v1.1.5-pre.37, on Mac OS X 10.14.2 18C54, locale
zh-Hans-CN)
• Flutter version 1.1.5-pre.37 at /Users/jinyulei/development/flutter
• Framework revision faae8bde78 (5 天前), 2018-12-28 23:03:40 -0500
• Engine revision 995e3247fe
• Dart version 2.1.1 (build 2.1.1-dev.0.1 88e6fe0f67)

[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
• Android SDK at /Users/jinyulei/Library/Android/sdk
• Android NDK at /Users/jinyulei/Library/Android/sdk/ndk-bundle
• Platform android-28, build-tools 28.0.3
• ANDROID_HOME = /Users/jinyulei/Library/Android/sdk
• Java binary at: /Applications/Android
Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build
1.8.0_152-release-1136-b06)
• All Android licenses accepted.

[!] iOS toolchain - develop for iOS devices (Xcode 10.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 10.1, Build version 10B61
✗ libimobiledevice and ideviceinstaller are not installed. To install with
Brew, run:
brew update
brew install --HEAD usbmuxd
brew link usbmuxd
brew install --HEAD libimobiledevice
brew install ideviceinstaller
• ios-deploy 1.9.4
• CocoaPods version 1.5.3

[✓] Android Studio (version 3.2)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 31.3.1
• Dart plugin version 181.5656
• Java version OpenJDK Runtime Environment (build
1.8.0_152-release-1136-b06)

[!] IntelliJ IDEA Community Edition (version 2018.3.2)
• IntelliJ at /Applications/IntelliJ IDEA CE.app
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
• For information about installing plugins, see
https://flutter.io/intellij-setup/#installing-the-plugins

[✓] Connected device (1 available)
• SM G9350 • 9e46eb63 • android-arm64 • Android 6.0.1 (API 23)

@jinyulei0710
Copy link
Author

@kangwang1988 The strangest thing is that ,after click to open FlutterPage some times, it maybe can go back.

@webyom
Copy link

webyom commented Feb 24, 2019

@kangwang1988 I met the same problem. I think the root cause is in the tryPopCurActivity method of FlutterWrapperActivity. I can't understand why the finish condition of the activity must be flutterWrapperInstCnt is greater than 1. When we start the first flutter activity from native activity, the flutterWrapperInstCnt is always 1, then we can never exit the flutter activity.

public void tryPopCurActivity() {
        if(flutterWrapperInstCnt>1){
            finish();
            saveFinishSnapshot(true);
        }
}

@webyom
Copy link

webyom commented Feb 24, 2019

@jinyulei0710 I see they have fixed this issue on master branch, but haven't publish it. You can switch to github master in your pubspec file.

@Mongolian
Copy link

Mongolian commented Feb 27, 2019

当调用类没有集成FlutterWrapperActivity 就会有问题
if(flutterWrapperInstCnt>=1){
finish();
saveFinishSnapshot(true);
}

这样?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants