Android Question [SOLVED] B4A 8.0 broke all of my apps

techknight

Well-Known Member
Licensed User
Not sure what exact change happened, but now all of my Apps are broken. None of my apps are for the play store, they are meant to be installed directly on the device because they are highly proprietary to the environment at which they are used.

But now, I keep getting this error:

java.lang.RuntimeException: Cannot change properties after call to SetInfo. Initialize the notification again.

Here is my code which has always worked in the past:

B4X:
    sNotif.Initialize
    sNotif.Icon = "icon"
    ClockTimer.Initialize("ClockTimer", 99)
    ClockStopped = True
    ClockTimer.Enabled = False
    HornTimer.Initialize("HornTimer", 100)
    HornTimer.Enabled = False
    sNotif.SetInfo("","",Main)
    sNotif.Sound = False
    sNotif.Notify(1)
    Service.StartForeground(1,sNotif)
How do I fix this? or is there a workaround? I have 80+ apps I now have to go through 1 by 1.

I am not using notifications at all, but I remember reading in the past about Sticky services and this was required to make a service stick. I have had android kill my services in the past with the app still open, causing the app to crash. Doing this fixed it.
 

JordiCP

Well-Known Member
Licensed User
From Erel's post regarding B4A 8.0
  • Notification object rewritten to work with targetSdkVersion 26. In most cases you don't need to change anything. Notification.SetInfo or Notification.SetInfo2 should be the last calls before you show the notification.
So it seems (not tested) that this ought to work?
B4X:
    sNotif.Initialize
    sNotif.Icon = "icon"
    ClockTimer.Initialize("ClockTimer", 99)
    ClockStopped = True
    ClockTimer.Enabled = False
    HornTimer.Initialize("HornTimer", 100)
    HornTimer.Enabled = False
    sNotif.Sound = False
    sNotif.SetInfo("","",Main)   '(to be tested) Only needed to move this line here?  
    sNotif.Notify(1)
    Service.StartForeground(1,sNotif)
 

Sagenut

Well-Known Member
Licensed User
Try reading here:
https://www.b4x.com/android/forum/threads/b4a-v8-0-has-been-released.90828/

There is a note about notifications:
Backward compatibility notes
  • Notification.SetInfo or SetInfo2 should be the last calls before you use the notification. Note that standard notifications created with previous versions of B4A will not work at all on Android 8+ when targetSdkVersion is 26+.
Hope it can help.


JordiCP was faster and better. ;)
 

KMatle

Expert
Licensed User
I fully understand Erel to rewrite some methods to work in the future. Of course some of the used code has to be changed by all of us like using runtime permissions.

But this is how a good support works. And to be honest: The "sticky service thing" was always "under attack" by Google. Now Oreo does it again. Android 9 will for sure bring new "features" which needs some code updating. Not a big thing. Just change it.
 

Cableguy

Expert
Licensed User
As a side note, You are/were not forced to update to V8. You could have gone the "Keep both v7.80 and V8" route, and separately manage OLD vs new projects...

So complaining about a new feature that will help everyone in a very near future, is like when the firsts security belts for cars showed up... many didn't like to use them, some still do, but they have become mandatory! because they can save your life! same goes with B4A v8
 

Erel

Administrator
Staff member
Licensed User
As explained here: [B4X] Backward Compatibility
Source code backward compatibility has the top priority. However the case here with notification is special:

1. You will soon be forced by Google to set the targetSdkVersion to 26+
2. Once you do it your current code, compiled with any version prior to B4A v8.0 will cause the app to crash on Android 8+ devices.

So the notification implementation was rewritten completely with best efforts to maintain backward compatibility. The only limitation is that the call to SetInfo should be the last call.
 

techknight

Well-Known Member
Licensed User
I have my apps running on my phone which is Android 8.1 and none of my apps are crashing when compiled with earlier versions of B4A so I am not quite sure I understand that statement, unless you mean once the source code is opened with 8.0, it cant be recompiled again with an older B4A?
 

techknight

Well-Known Member
Licensed User
As a side note, You are/were not forced to update to V8. You could have gone the "Keep both v7.80 and V8" route, and separately manage OLD vs new projects...
When an update comes out, I am going to update. its just the nature of the beast, right? Its just painful that one piece of the puzzle is broken so I have to go through and spend hours reworking code and fixing it. BUT thats my problem and nobody elses, and I guess its just the nature of the game if you wanna play. Right? I am lazy, I admit it. But again thats not yalls problem.
 

Erel

Administrator
Staff member
Licensed User
As written in my signature, all Android developers should read this tutorial:
android.jar / targetSdkVersion / minSdkVersion

The question or issue raised in this thread is explained in the release notes: B4A v8.0 has been released!

The reasoning behind it is explained in post #7.
And as I wrote in that post:

1. You will soon be forced by Google to set the targetSdkVersion to 26+
2. Once you do it your current code, compiled with any version prior to B4A v8.0 will cause the app to crash on Android 8+ devices.

If you have any other question then please start a new thread. However make sure to first read the above tutorial and release notes.
 

ivan.tellez

Active Member
Licensed User
When an update comes out, I am going to update. its just the nature of the beast, right? Its just painful that one piece of the puzzle is broken so I have to go through and spend hours reworking code and fixing it. BUT thats my problem and nobody elses, and I guess its just the nature of the game if you wanna play. Right? I am lazy, I admit it. But again thats not yalls problem.
Google will force you to update ALL your apps any way. Now with B4A 8 you can start updating them instead of doing all at once when the deadline arrives.
 

techknight

Well-Known Member
Licensed User
Yea possibly. But I dont use the play store. Only way they can force that is if they change the rules in the android runtime itself.
 

canalrun

Well-Known Member
Licensed User
Google will force you to update ALL your apps any way. Now with B4A 8 you can start updating them instead of doing all at once when the deadline arrives.
I continue to see seemingly conflicting information about the requirements for existing apps after November 2018.

This is a quote from Erel's tutorial thread in December 2017:
No. Quoting Google's blog:
This will be required for new apps in August 2018, and for updates to existing apps in November 2018.

At this point it only affects updates to existing apps. So as long as an existing app is not updated it will continue to run without this restriction.
Has this information changed?

I plan to do any upgrades to existing apps well before November 2018 – they will never be updated after that. They will all have TargetSDKVersion below 26 (probably around 19)

I am hoping these apps will continue to work in all current and future versions of Android (including 8+) without restriction.

Is this true?

Barry.
 

techknight

Well-Known Member
Licensed User
From what I understand, it only affects the play store and whether Google accepts or rejects it.
 

leitor79

Active Member
Licensed User
When an update comes out, I am going to update. its just the nature of the beast, right? Its just painful that one piece of the puzzle is broken so I have to go through and spend hours reworking code and fixing it. BUT thats my problem and nobody elses, and I guess its just the nature of the game if you wanna play. Right? I am lazy, I admit it. But again thats not yalls problem.
Not sure about this. You should check compatibility issues before doing an update. If you had a desktop PC with windows XP and Office 2010 and try to update to office 2013 when it came out, you won't be blaming microsoft for the new office version not running in your system.
 
Top