Hello, i am working on an Android app that should be opened by clicking on push notification when the app is not running. I tried to implement this part in documentation, but i am not Android developer and can not accomplish it. I have this error:
../android/app/src/main/java/labs/webbing/me/MyReactNativeHost.java:89: error: not an enclosing class: MainApplication
new CodePush(BuildConfig.CODEPUSH_KEY, MainApplication.this, BuildConfig.DEBUG)
^
My _MainApplication.java_ looks like this:
package my.app.com;
public class MainApplication extends Application implements ReactApplication {
private final MyReactNativeHost mReactNativeHost = new MyReactNativeHost(this);
@Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
@Override
public void onCreate() {
CodePush.setReactInstanceHolder(mReactNativeHost);
super.onCreate();
}
}
My _MyReactNativeHost.java_ sits in the same folder and looks like this:
package my.app.com;
public final class MyReactNativeHost extends ReactNativeHost implements ReactInstanceHolder {
MyReactNativeHost(Application application) {
super(application);
}
@Override
protected String getJSBundleFile() {
return CodePush.getJSBundleFile();
}
@Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
// .. alot of different packages
new CodePush(BuildConfig.CODEPUSH_KEY, MainApplication.this, BuildConfig.DEBUG)
);
}
}
What am i missing? Thanks a lot!
Hi @cherniv, thanks for reaching as, could you please take a look at MainActivity.java and MainApplication.java files from our example app and let me know if you have any questions?
Hi @sergey-akhalkov , i'm trying to implement more advanced case, based on this: https://github.com/Microsoft/react-native-code-push/blob/master/docs/setup-android.md#background-react-instances . My React Native version is 0.44, this is relevant to the "For React Native >= v0.29" part.
Ok i think i solved the syntax issue like this:
public class MainApplication extends Application implements ReactApplication {
public class MyReactNativeHost extends ReactNativeHost implements ReactInstanceHolder {
MyReactNativeHost(Application application) {
super(application);
}
@Override
protected String getJSBundleFile() {
return CodePush.getJSBundleFile();
}
@Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new ReactNativePushNotificationPackage(),
new ReactNativeAudioStreamingPackage(),
new CodePush(BuildConfig.CODEPUSH_KEY, MainApplication.this, BuildConfig.DEBUG)
);
}
}
private final MyReactNativeHost mReactNativeHost = new MyReactNativeHost(this);
@Override
public void onCreate() {
CodePush.setReactInstanceHolder(mReactNativeHost);
super.onCreate();
}
@Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
}
But it is still crashing when the app is in background and it is opened from a push notification.
Hi @cherniv, got it, thanks for your reply.
But it is still crashing when the app is in background and it is opened from a push notification.
Could you please create new issue and provide us more info about it, so we would able to investigate it and help you?
Hi @sergey-akhalkov , i figured out that code-push is not a reason for crash, but another third-party plugin . Sorry for bothering!
P.S. Link to their issue: https://github.com/tlenclos/react-native-audio-streaming/issues/101
@cherniv, got it, thanks for the information!
I can confirm it is the way to enable codepush update when opening outside from activity.
I had several errors while trying to do what the doc says like
error: class MyReactNativeHost is public, should be declared in a file named MyReactNativeHost.java
public class MyReactNativeHost extends ReactNativeHost implements ReactInstanceHolder
@sergey-akhalkov , the doc about background react instances should be updated with the syntax from @cherniv.
I tried to update from a push notification and it's working well.
@sergey-akhalkov PR done
https://github.com/Microsoft/react-native-code-push/pull/1459
Most helpful comment
Hi @sergey-akhalkov , i figured out that code-push is not a reason for crash, but another third-party plugin . Sorry for bothering!
P.S. Link to their issue: https://github.com/tlenclos/react-native-audio-streaming/issues/101