androidx.navigation:navigation-fragment:2.2.0, get "You must call removeView() on the child's parent first." on navController.popBackStack() - android-databinding

I like use data binding and navigation graph. But after update androidx dependencies from androidx.navigation:navigation-fragment:2.0.0 on 2.2.0 application is crashed after press button "Back". Crash always after return from other fragment to previous fragment containing FragmentPagerAdapter.
in build.gradle
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
// This is work
// implementation 'androidx.appcompat:appcompat:1.0.2'
// implementation 'androidx.navigation:navigation-fragment:2.0.0'
// This generate error after backstack
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.navigation:navigation-fragment:2.2.0'
}
For see a problem and getting error, please download example from https://github.com/ABRadzh/ErrorNavigation. Otherwise it will be difficult for me to explain where the error occurs.
Press on any button on any page.
Press hardware "Back" button.
Get error message:
2020-02-11 16:15:13.119 2429-2429/in.pagerview.navigation.databinding.onbackstack E/AndroidRuntime: FATAL EXCEPTION: main
Process: in.pagerview.navigation.databinding.onbackstack, PID: 2429
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
at android.view.ViewGroup.addViewInner(ViewGroup.java:4954)
at android.view.ViewGroup.addView(ViewGroup.java:4785)
at androidx.viewpager.widget.ViewPager.addView(ViewPager.java:1485)
at android.view.ViewGroup.addView(ViewGroup.java:4725)
at android.view.ViewGroup.addView(ViewGroup.java:4698)
at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:326)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1187)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1356)
at androidx.fragment.app.FragmentManager.moveFragmentToExpectedState(FragmentManager.java:1434)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1497)
at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:2625)
at androidx.fragment.app.FragmentManager.dispatchActivityCreated(FragmentManager.java:2577)
at androidx.fragment.app.Fragment.performActivityCreated(Fragment.java:2722)
at androidx.fragment.app.FragmentStateManager.activityCreated(FragmentStateManager.java:346)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1188)
at androidx.fragment.app.FragmentManager.addAddedFragments(FragmentManager.java:2224)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1997)
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1953)
at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1849)
at androidx.fragment.app.FragmentManager$4.run(FragmentManager.java:413)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6719)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:449)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
But all code for transition fragment and data binding is generated automatically. I do not known where i must call removeView().
If you try to use old dependencies, then invert all comments in code and layouts. And popBackStack() will work correctly.
I do not found anything about this error. May be, I do something incorrect?

The solution is just to add this code to every fragment:
#Override
public void onDestroyView() {
super.onDestroyView();
if(binding.getRoot().getParent() != null)
((ViewGroup)binding.getRoot().getParent()).removeView(binding.getRoot());
}
I really recommend you to create a BaseFragment which has this code and every fragment will extends from it, so you will not have to repeat the code on every fragment class.

Related

why popbackstack removes the action/destination from the fragment?

I'm building a notes application basically a clone of keep notes.
I want to save the note when the user press back button from the createNotesFragment and pop the fragment from the stack to move back to the homeFragment.
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
requireActivity()
.onBackPressedDispatcher
.addCallback(this) {
saveNote()
activity?.supportFragmentManager?.popBackStack()
}
}
the navigation from the homeFragmet works fine but after adding one note when I try to move back to the createNotesFragment. It shows me this error.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.lavanianotesapp, PID: 7351
java.lang.IllegalArgumentException: Navigation action/destination com.example.lavanianotesapp:id/action_homeFragment_to_createNotesFragment cannot be found from the current destination Destination(com.example.lavanianotesapp:id/createNotesFragment) label=fragment_create_notes class=com.example.lavanianotesapp.UI.Fragments.CreateNotesFragment
at androidx.navigation.NavController.navigate(NavController.kt:1540)
I don't understant before popBaCckStack it works fine but after I pop the fragment it doesn't works.
Thanks in advance.

Dealing with R8 + JvmStatic Annotation + Lambda in public API for Android Library written in Kotlin

First of all, please note that I'm not expecting why do you want to obfuscate library comments. This is a genuine problem I'm asking about.
I have been having an issue dealing with R8/obfuscation with an Android library written in Kotlin.
I've a public API method which is annotated with #JvmStatic and that method takes a Lambda as parameter.
For example, take a look at code below,
typealias MyLambdaCallback = (String, Map<String, Any>) -> Unit
#Keep
object MyApi {
private var callback: MyLambdaCallback? = null
#JvmStatic
fun setCallback(callback: MyLambdaCallback) {
this.callback = callback
}
}
I have added #Jvmstatic so that Java calling code can call the method statically rather than doing MyApi.INSTANCE.setCallback()
When I release the library without minification, everything is fine and calling code from both Java and Kotlin is written as expected.
But now I want to release the library while turning on minification.
That creates an issue.
Here is the error
java.lang.IncompatibleClassChangeError: The method 'void setCallback(kotlin.jvm.functions.Function2)' was expected to be of type virtual but instead was found to be of type static (declaration of 'com.demo.basic.Application' appears in /data/app/com.demo.basic-_0uJXPbtfs3UZ2Rp2h-RdQ==/base.apk!classes2.dex)
Am I making a mistake somewhere or this is expected as some kind of limitation ?
What did I Try ?
Removing #Jvmstatic resolves the issue but it created ugly Java calling code
Kept #Jvmstatic but removed Lambda converting Lambda into an interface with one method and everything is working fine. Unfortunately SAM for Kotlin classes is not there yet, so calling Kotlin code looks ugly.
This is tracked on the R8 issue tracker http://issuetracker.google.com/158393309 which has more details.
The short story is that this has been fixed in R8 version 2.1.35, which can be used by making the following changes to the top level build.gradle file:
repositories {
maven {
url 'https://storage.googleapis.com/r8-releases/raw'
}
}
dependencies {
classpath 'com.android.tools:r8:2.1.35' // Must be before the Gradle Plugin for Android.
classpath 'com.android.tools.build:gradle:X.Y.Z' // Your current AGP version.
}
R8 team has fixed this issue along with related issue b/158400283 in R8 version 2.1.42
Fix should already be available in Android Studio 4.1 beta or higher, but if you're using stable Android Studio 4.0 then add following to your top-level build.gradle file:
buildscript {
repositories {
maven {
url 'https://storage.googleapis.com/r8-releases/raw'
}
}
dependencies {
classpath 'com.android.tools:r8:2.1.42' // Must be before the Gradle Plugin for Android.
classpath 'com.android.tools.build:gradle:X.Y.Z' // Your current AGP version.
}
}

React native twitter sign in

I installed twitter login for react native and I get this error on
apply plugin: 'Crashlytics' from your library project. If you're looking for Library support, please contact support#fabric.io
:react-native-twitter-signin:generateReleaseResValues
:react-native-twitter-signin:generateReleaseResources
:react-native-twitter-signin:mergeReleaseResources
:react-native-twitter-signin:processReleaseResources
:react-native-twitter-signin:generateReleaseSources
:react-native-twitter-signin:incrementalReleaseJavaCompilationSafeguard
:react-native-twitter-signin:compileReleaseJavaWithJavac
:react-native-twitter-signin:compileReleaseJavaWithJavac - is not incremental (e.g. outputs have changed, no previous execution, etc.).
/Users/khalidahmada/www/travelStory/node_modules/react-native-twitter-signin/android/src/main/java/com/goldenowl/twittersignin/TwitterSigninModule.java:32: error: TwitterSigninModule is not abstract and does not override abstract method onNewIntent(Intent) in ActivityEventListener
public class TwitterSigninModule extends ReactContextBaseJavaModule implements ActivityEventListener {
^
/Users/khalidahmada/www/travelStory/node_modules/react-native-twitter-signin/android/src/main/java/com/goldenowl/twittersignin/TwitterSigninModule.java:88: error: method does not override or implement a method from a supertype
#Override
^
2 errors
:react-native-twitter-signin:compileReleaseJavaWithJavac FAILED
Any idea about this error? I'm JavaScript Developer and I have no idea about this error.
This is the node module:
react-native-twitter-signin
delete #override at selected file .code will work fine...

Adding PatternMatchListener to Eclipse Console in which stage of View Lifecycle

I am developing an Eclipse plug-in which will be triggered by a specific pattern string found (e.g., stack trace) in the default console opened in Eclipse and will show some notification in a custom view. I know how add the listener to the available consoles.But I am not sure in which phase of Eclipse View life cycle I need to add the listener. Currently I am adding in createPartControl which is not what I want, because it forces to me to open the view manually to perform the binding the listener with the consoles.
public void createPartControl(Composite parent) {
//got the default console from ConsolePlugin
TextConsole tconsole=(TextConsole)defaultConsole;
tconsole.addPatternMatchListener(new IPatternMatchListener() {
// implementation codes goes here
}
}
Any help will be appreciated.

The hierarchy of the type AddEntryAction is inconsistent (Jface)

i have the following class in eclipse
class AddEntryAction extends Action {
public AddEntryAction() {
super("Add Entry");
setToolTipText("Add Entry");
}
public void run() {
WizardDialog dlg = new WizardDialog(MainClass.mainWindow.getShell(),
new AddEntryWizard());
dlg.open();
}
}
and Action class extends AbstractAction which intern extends EventManager class. Both these parent classes are part of the eclipse SWT/jface libraries... I get the following error on the above class declaration
The project was not built since its
build path is incomplete. Cannot find
the class file for
org.eclipse.core.commands.common.EventManager.
Fix the build path then try building
this
project DisplayExample Unknown Java
Problem
The type
org.eclipse.core.commands.common.EventManager
cannot be resolved. It is indirectly
referenced from required .class
files MainClass.java /DisplayExample/src line
94 Java Problem
AddEntryAction is declared within the same source file MainClass.java. Actually, this is an example from Java2s.com ... I have the libraries/jars because i can see the compiles classes of all these clases
The error "The project was not built since ... org.eclipse.core.commands.common.EventManager cannot be resolved..." with swt/jface dependencies can be caused by missing reference sources or binaries containing org.eclipse.core packages in addition to org.eclipse.swt and org.eclipse.jface packages.
E.g. build path in my case included:
swt.jar
org.eclipse.jface_3.4.2.M20090107-0800.jar
Following jar was missing and caused above error:
org.eclipse.core.commands_3.4.0.I20080509-2000.jar