Questions tagged [stateflow]

StateFlow is a toolbox from MathWorks for development of state machines. For questions regarding the StateFlow interface from Kotlin's kotlinx.coroutines library, use the [kotlin-stateflow] tag instead.

Stateflow is an toolbox (extension) of Matlab from Mathworks. It is a commercial, and proprietary toolset.

Generally, Stateflow extends Simulink with the ability to design and test state machines. It is commonly used in control design, where algorithms can be either MATLAB scripts & formulas, Simulink blocks or embedded code (in the form of so-called S-functions).

Code generation is supported on the host platform, but for target code additional tools are required (such as Simulink Real-Time (previously known as real time Workshop) or Embedded Coder).

Advantages compared to software-only tooling (like IBM Rhapsody):

  • use with hardware (in the loop)
  • seamless integration with Simulink

Disadvantages compared to software-only tooling:

  • high license cost for code generation

Links:

131 questions
0
votes
1 answer

How can I use StateFlow with LinearProgressIndicator to show progress

I'm new to Compose framework and StateFlows. I want LinearProgressIndicator to show progress that will be emitted from downloadProgress StateFlow. How can I achieve that? @Composable fun DownloadProgressDialog( downloadProgress:…
0
votes
1 answer

StateFlow in RecyclerView emitting same values for every row

I have an Android ViewModel that manages a recyclerView with ImageView in each row where I'm setting a userId string in a StateFlow. I want to use that userId to retrieve the user's description as another StateFlow. I'm doing this: class…
VIN
  • 6,385
  • 7
  • 38
  • 77
0
votes
0 answers

Update state value when using stateIn operator

I have a usecase that i combine two flows and convert it to stateFlow by using statIn. When user clicks on the list, i want to update current ui state and pass it to my stateflow. Since it's not MutableStateFlow, i am not able to update it. The…
Berkay Kireçci
  • 651
  • 5
  • 18
0
votes
0 answers

When using StateFlow and DataBinding together, the BindingAdapter's method is called twice

MainActivity class MainActivity : AppCompatActivity() { private val viewModel: MainViewModel by lazy { ViewModelProvider(this).get(MainViewModel::class.java)} private lateinit var binding: ActivityMainBinding override fun…
wantique
  • 1
  • 1
0
votes
1 answer

Properly use a loop in coroutine to place rest api call

I am currently building a Flickr-like app and I do have a question about pagination. I am currently calling a FlickrApi to retrieve the recent photos. It's working well but I only get the first 100 because the api only returned list of photos using…
Seb
  • 2,929
  • 4
  • 30
  • 73
0
votes
1 answer

When using ShareFlow and StateFlow, the app displays the same value when it comes back from the background

I'm currently using StateFlow and SharedFlow on Android. When subscribe to SharedFlow in ViewModel in Activity, using repeatOnLifecycle() to cancel and resume subscription according to lifecycle. The first time. run the app in this state, show toast…
0
votes
1 answer

how to disable Stateflow object eliminated by optimization while code generation?

I have designed a state machine in stateflow. it consists of several variable and states. however, when I am generating code using embedded Coder, multiple states, variables and even transitions are missing from code. on clicking on that particlar…
0
votes
3 answers

Common way to handle form state in StateFlow in Android

I am trying to implement an form screen with many EditTexts, Switches, etc. I have a fragment with viewBinding and viewModel that holds a StateFlow "formData". Every field in UI have its own field in those formData. I created listeners for the…
Baterka
  • 3,075
  • 5
  • 31
  • 60
0
votes
2 answers

StateFlow doesn't emit initial value

I have an empty list as initial value to show skeleton loadings on recyclerview but the problem is the initial value doesn't get emmited when collected inside fragment and only receive the second value emitted from ViewModel after loading…
0
votes
2 answers

SharingStarted.WhileSubscribed vs Lazily

There is SharingStarted.WhileSubscribed and SharingStarted.Lazily both are used Flow.stateIn() of Android Platform. I read the explanation in the official documentation, asked chatgpt, and googled it. But I'm not sure what the difference between the…
PJH
  • 90
  • 9
0
votes
1 answer

Can two collect be used with the same StateFlow?

I am trying to understand the use of flow in Kotlin and I was trying different codes, in particular I was with this method: val stateFlow = MutableStateFlow(0) private fun stateFlowWithContinueCollect() { runBlocking { launch { …
Ludiras
  • 338
  • 3
  • 20
0
votes
0 answers

Is that possible to throw errors with respect to a StateFlow in the view model and catch them in the activity?

I am using StateFlow to host UI states and MutableStateFlow as backing property in my ViewModel class. Let's suppose my property is called uiState and initialized as follows: private var _uiState = MutableStateFlow(SomeData(message="NONE")) val…
0
votes
0 answers

MutableStateFlow with MutableList for big lists (Android Jetpack Compose)

I'm trying to figure out the best way to handle large lists in the ViewModel that you want to expose to the UI. Here is my approach for small lists setContent { val users by viewModel.users.collectAsState() ... } class MainViewModel :…
Wolfscowl
  • 1
  • 1
0
votes
2 answers

Android Kotlin StateFlow - Does not emit new Value with value.copy()

I'm trying to figure out what the best practice is in ViewModel. StateFlow, LiveData or ComposeState. Now I have come across something that I can't explain. Activity: val viewModel by viewModels() setContent { val randomAdmin…
Wolfscowl
  • 1
  • 1
0
votes
0 answers

Save Flow value accross navigation (back and return) in Jetpack Compose

I have a MutableStateFlow value coming from PreferencesDataStore. My Default value is "Newspaper.Undefined" and i can expose a new value when i'm clicking a button (from Newspaper.Undefined to Newspaper.SecondValue). The probleme is, when i'm…
Mehdi.ncb
  • 346
  • 3
  • 13
1 2 3
8 9