state

Android: Check if service is running via. bindService

荒凉一梦 提交于 2019-12-05 09:53:43
问题 What would be the best way to check if an Android Service is running? I am aware of the ActivityManager API, but it seems like the use of the API is not advised for the scenarios similar to mine (source). I am also aware of the possibility of using global/persistent variables to maintain the state of a service. I have tried to use bindService with flags set to 0 , but I got the same problems as the person on the source link (the only exception was, I was trying the bindService with a local

How to Better Iterate over State in Clojure (monad?)

落爺英雄遲暮 提交于 2019-12-05 06:47:43
I just wrote this code: (defn parameters [transform-factory state] (lazy-seq (let [[r1 state] (uniform state) [r2 state] (uniform state) [t state] (transform-factory state)] (cons [t [r1 r2]] (parameters transform-factory state))))) (defn repeated-transform [mosaic n transform-factory state] (reduce transform-square mosaic (take n (parameters transform-factory state)))) the parameters function generates a lazy sequence of values generated from the state , which are used to parameterise a repeated transformation of something (a "mosaic" in this case). it seems to me that parameters shows a

Replacing if/else logic with state/strategy pattern

故事扮演 提交于 2019-12-05 05:53:52
I have read the previous stack exchanges on replacing conditional logic in Java such as IF/ELSE with State/Strategy patterns but I am not sure whether my case is a proper fit for the replacement. Here are coupled I looked at - Long list of if statements in Java and Converting many 'if else' statements to a cleaner approach I am essentially writing a file download manager and these are my IF/ELSE constructs: If the file and it's zip file exist then move zip file to zip file directory and read in file If the zip file exists then unzip file and move zip file to zip file directory and read in file

How to listen to localstorage in react.js

笑着哭i 提交于 2019-12-05 05:40:53
I'm having a problem with a component that gets data from an array in localstorage. It gets the initial data when the page loads, but how do I update when localstorage is changed? import React, {Component} from 'react'; class MovieList extends Component { constructor(props){ super(props) this.state = { filmList: [] } } componentWillMount(){ var film = [], keys = Object.keys(localStorage), i = keys.length; while ( i-- ) { film.push( localStorage.getItem(keys[i])) } this.setState({filmList: film}) }; render(){ return( <ul> <li>{this.state.filmlist}</li> </ul> ); } } export default MovieList; Per

How to avoid downcast?

爷,独闯天下 提交于 2019-12-05 05:09:07
I have an implementation of a State Pattern where each state handles events it gets from a event queue. Base State class therefore has a pure virtual method void handleEvent(const Event*) . Events inherit base Event class but each event contains its data that can be of a different type (e.g. int, string...or whatever). handleEvent has to determine the runtime type of the received event and then perform downcast in order to extract event data. Events are dynamically created and stored in a queue (so upcasting takes place here...). I know that downcasting is a sign of a bad design but is it

Pass state from child to parent component in React Native

筅森魡賤 提交于 2019-12-05 04:47:06
My app has a settings screen (child component) where you can change information about yourself and I'm trying to get that to render on my app's profile screen (parent component). So the profile screen displays your info and if you want to change any info you do it in settings. Right now any changes I make in the settings screen show up in Firebase but if I go back to the profile screen the changes in settings don't render. Of course if I close the app and reload it the changes will be there because the changes in settings are registering to firebase; however, the state is not passing up from

Structuring state management store (ngrx/redux). Flat as representative of data, or nested as representative of view?

╄→гoц情女王★ 提交于 2019-12-05 04:46:59
I'm using ngrx store, to maintain application state, normalizr to flatten my data from API calls and Immutable. So far it's been working really well, but I'm getting to some more complex data relationships and I was wondering how to proceed with structuring the store. To simplify things, I have two sets of objects. Sessions, and Invoices. One user logs on and can view his list of Sessions. The state in the store is held in an object ISessions : export interface ISessions extends Map<String, any> { result: List<Number>; entities: { sessions: Map<Number, ISessions>, clients: Map<Number, IClient>

Haskell : reference to previously updated elements of list within the update function

雨燕双飞 提交于 2019-12-05 03:42:47
Say I have the following definitions data Book = Book {id :: Int, title :: String} type Shelf = [Book] Assuming I have a hypothetical function (upd is for update) updShelf :: Shelf -> Shelf updShelf all@(book : books) = updBook book : updShelf books All fine so far. Now let's say the updateBook function needs to refer to the updated book three books before it i.e updateBook for book at position 5 in bookshelf need to refer to book at position 2 (assume first three books need no such reference to update). No problem, I say, and modify my code as such: updShelf :: Shelf -> Shelf updShelf all@

Propagation of State Monad

会有一股神秘感。 提交于 2019-12-05 02:09:15
问题 I have the following function for walking around "edges" of the "graph" of my game world. It alters the state of the world--specifically, the player's location. I need to report a message alerting the player of their change in location as well. So I could either return a tuple of (message, newWorld), or I could use a State monad. (Right? I'm new to this stuff.) Here's my attempt at the monad approach: walk dir = do world <- get let attempt = filter (\e -> edgeDirection e == dir) $ edges edges

Should you connect and disconnect to Google Play Services in each activity?

天大地大妈咪最大 提交于 2019-12-05 02:05:06
问题 I am writing an application which needs a connected location client in all the activities. How do the manage the state of the client? I want to call the mLocationClient.connect() only once to avoid hassle, and should be able to remove location updates / disconnect when the application stops. How do I keep the location client connected across all activities, assuming I have connected to it in the splash screen Activity ? Another question that arises here is, when I resume the paused