Application initialization in client side set up for SDK for Android/Java

Hello,

I’m running through the documents for client side set up for SDK for Android/Java, it’s unclear which file the following should be placed in:

From the video on the push commander missions it looks like it may be MainActivity.java

So I’ve added it in there:

I am getting errors when I try to run the app:

That I think are coming because of this:

In the missions video, it says that this is red if backendless hasn’t been added as a dependency in the app build.gradle file, but it has:

Any help gratefully accepted!

Hi @Luc_Zentar ,

The errors which you have received caused by wrong syntax of your Kotlin code.

In example which you have referenced initialization performed inside of onCreate method. In your code you placed initialization just inside of your class declaration. I am not familiar with Kotlin very well but it seems wrong. You should perform initialization inside constructor or init method of activity.

Also in your code you have one more problem - you have initialized SDK too many times.
You can try something like this

class MainActivity: FlutterActivity() {
    init {
        Backendless.initApp( this, "your-domain.com" )
    }
}

Could you please make suggested changes and write me back about results?

Regards, Andriy

Thanks @Andriy_Konoz but it didn’t work.

The code is all from Backendless, the initial app build is from the git repository here - GitHub - Backendless/native-mobile-app-shell: Mobile native app shell is a native wrapper for a UI Builder application. It can be used to package a UI Builder app so it can run on a mobile device in a hybrid mode. The app can be published to the Apple and Google Play stores. with my UI Builder files added.

Then I have added to some of the Android files based on the instructions here - Push Notification Setup (Android) - Backendless SDK for Android/Java API Documentation

Where it has been difficult is that the missions video shows the MainActivity file as a .java file but Android Studio uses .kt instead. Also the FCM services is different in the GIT download (I’m not sure if this matters or not), so I haven’t been able to just follow the exact steps in the documentation and the video.

This whole process isn’t something I properly understand, so I’m not sure if this is even a question for Backendless anymore or if the issue lies elsewhere in the different Android files. But if there is anything you can do to help with getting this fixed and the device registration working, that would be great.

@Luc_Zentar ,

To clarify situation - you have taken Android code from Flutter project and created your own Android project, am I right?

Could you please provide code of MainActiviy class and text of errors which you receive now?

Regards, Andriy

@Andriy_Konoz

That is correct. I uninstalled the project and started again from the beginning. I also found this, which explained the errors I was getting in the Manifest. When I loaded the Android file as the top project in Android Studio it synced Gradle and resolved all of those errors.

Now the problem I have is just in MainActivity:

Code

Errors

Hello @Luc_Zentar

Look’s like you try to edit the Android part in the Flutter project, I think it is could be not correct.
Besides, it looks like you ignored Andrew’s advice.

In example which you have referenced initialization performed inside of onCreate method. In your code you placed initialization just inside of your class declaration. I am not familiar with Kotlin very well but it seems wrong. You should perform initialization inside constructor or init method of activity.

Also, looks like your problems are not related to our services.

Regards,
Viktor

@viktor.liablin I think the problems do come from Flutter, so I will try to learn more about that.

Some feedback though, I am only using Flutter because this is Backendless’ suggestion for packaging my app from UI Builder into a native app.

I’ve used the github code from Backendless and followed the instructions from there, but this isn’t much use to me without the ability to send push notifications or request camera access.

I will start to learn about flutter and the different coding needed for the files, but this takes me away from the ‘no code’ approach that Backendless has enabled up until now.

I think it would be easier for your customers if you built the push notifications and other native app access requests into the github instructions for packing with Flutter, or if the instructions here were updated to explain how to do this with flutter:

https://backendless.com/docs/android/push_push_notification_setup_androi.html

Hello @Luc_Zentar

Thank you for your response.
Soon we will have instructions for setting up a push notification for the native app shell.

Regards,
Inna

1 Like