• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 11:01
CEST 17:01
KST 00:01
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
ByuL, and the Limitations of Standard Play3Team Liquid Map Contest #22: Results and Winners7Code S Season 2 (2026): RO4 and Finals Preview12TL.net Map Contest #22 - Voting & Ladder Map Selection7Code S Season 2 (2026) - RO8 Preview8
Community News
MC vs IdrA, Boxer vs Nal_rA to be Legacy Matches @ BlizzCon175.0.16 Hotfix (June 30) - Balance + Bug Fixes20Weekly Cups (June 22-28): Zergs thrive in new patch2[TLMC] Summer 2026 Ladder Map Rotation05.0.16 patch for SC2 goes live (8 worker start)99
StarCraft 2
General
MC vs IdrA, Boxer vs Nal_rA to be Legacy Matches @ BlizzCon 5.0.16 Hotfix (June 30) - Balance + Bug Fixes 5.0.16 patch for SC2 goes live (8 worker start) Is the larve respawn broken? ByuL, and the Limitations of Standard Play
Tourneys
RSL Revival: Season 6 - Qualifiers and Main Event Douyu Cup 2026: $20,000 Legends Event (June 26-28) Maestros of The Game 2 announcement and schedule ! INu's Battles#17 <BO.9> Sparkling Tuna Cup - Weekly Open Tournament
Strategy
[G] Having the right mentality to improve
Custom Maps
New Map Maker - Looking for Advice - Love or Hate Work In Progress Melee Maps [D]RTS in all its shapes and glory <3
External Content
The PondCast: SC2 News & Results Mutation # 532 Nuclear Family Mutation # 531 Experimental Artillery Mutation # 530 One For All
Brood War
General
ASL 22 Proposed Map Pool ProGamer Paychecks Story BW General Discussion Best thing happen to StarCraft since Remastered? Data needed
Tourneys
[Megathread] Daily Proleagues [ASL21] Grand Finals The Casual Games of the Week Thread [BSL22] GosuLeague Casts - Tue & Thu 22:00 CEST
Strategy
Simple Questions, Simple Answers Creating a full chart of Zerg builds Relatively freeroll strategies Why doesn't anyone use restoration?
Other Games
General Games
ZeroSpace at Steam NextFest - Last free demo Nintendo Switch Thread Path of Exile Stormgate/Frost Giant Megathread Beyond All Reason
Dota 2
Looking for a Dota Mentor Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug
TL Mafia
[94721]Better Good-Health Signs Than 3-15 Bans/Yea TL Mafia Community Thread Vanilla Mini Mafia
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread Men's Fashion Thread Canadian Politics Mega-thread The Games Industry And ATVI
Fan Clubs
The HerO Fan Club! The herO Fan Club!
Media & Entertainment
Movie Discussion! Series you have seen recently... [Req][Books] Good Fantasy/SciFi books [TV/BOOK] *SPOILERS* Game of Thrones Discussion
Sports
2024 - 2026 Football Thread TeamLiquid Health and Fitness Initiative For 2023 Formula 1 Discussion McBoner: A hockey love story Cricket [SPORT]
World Cup 2022
Tech Support
How to clean a TTe Thermaltake keyboard? Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List
Blogs
Listen To The Coaches!
TrAiDoS
An Exploration of th…
waywardstrategy
I'm an arrogant trash talke…
FlaShFTW
Gauntlet SC2: A Retrospectiv…
Ctone23
ramps on octagon
StaticNine
Funny Nicknames
LUCKY_NOOB
Evil Gacha Games and the…
ffswowsucks
Customize Sidebar...

Website Feedback

Closed Threads



Active: 3699 users

The Big Programming Thread - Page 959

Forum Index > General Forum
Post a Reply
Prev 1 957 958 959 960 961 1032 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
WarSame
Profile Blog Joined February 2010
Canada1950 Posts
May 15 2018 04:16 GMT
#19161
I have a task in my Android app that needs to run asynchronously. It contributes to the UI and requires context(needs an object from the Application). Do I use an AsyncTask, Fragment, or something else?
Can it be I stayed away too long? Did you miss these rhymes while I was gone?
berated-
Profile Blog Joined February 2007
United States1134 Posts
Last Edited: 2018-05-15 11:07:27
May 15 2018 11:06 GMT
#19162
On May 15 2018 13:16 WarSame wrote:
I have a task in my Android app that needs to run asynchronously. It contributes to the UI and requires context(needs an object from the Application). Do I use an AsyncTask, Fragment, or something else?


I personally always thought the fragment thing was a hack. We ultimately use loaders for this type of stuff, but async task can work. You just need to make sure that when the async task runs on the main thread that you realize the activity that started it could be destroyed.

Disclaimer most this information is from Android 2 years ago, don't know if they have new options but that looks like the same stuff.
Acrofales
Profile Joined August 2010
Spain18336 Posts
May 15 2018 11:15 GMT
#19163
On May 15 2018 20:06 berated- wrote:
Show nested quote +
On May 15 2018 13:16 WarSame wrote:
I have a task in my Android app that needs to run asynchronously. It contributes to the UI and requires context(needs an object from the Application). Do I use an AsyncTask, Fragment, or something else?


I personally always thought the fragment thing was a hack. We ultimately use loaders for this type of stuff, but async task can work. You just need to make sure that when the async task runs on the main thread that you realize the activity that started it could be destroyed.

Disclaimer most this information is from Android 2 years ago, don't know if they have new options but that looks like the same stuff.

Doing UI stuff from asynctasks is a bit finicky. You need to use a Handler, and ensure the UI element you want to manipulate still exists (and the activity that called it is still there). However, it is one of the better ways in Android for short little things. If what you want is something persistent, you should probably use an intentservice or a futuretask (interaction with the UI is similarly finicky or even more so).

Fragment has the advantage that it is a UI element, so changing the UI is easy. However, doing computation on the UI thread is a terrible idea, and if you want to run stuff asynchronously, Fragments are not the place for it: they will block the UI, and cause your app to stall/crash/get killed.
WarSame
Profile Blog Joined February 2010
Canada1950 Posts
May 15 2018 15:30 GMT
#19164
Yes, Fragment runs on the main thread. I tried it and couldn't handle the 1/2 second delay.

I tried it as an AsyncTask, too, and that seemed to work fine but I was wondering if there was a "better" Android way to do it.

From what I've read and experienced it seems hard to pass data back from an IntentService to a particular Activity. I've mostly been sending information to the user from them in Notifications.

I'll look into FutureTask.
Can it be I stayed away too long? Did you miss these rhymes while I was gone?
Hanh
Profile Joined June 2016
146 Posts
May 15 2018 23:44 GMT
#19165
Changes to your model data shouldn't be coupled with UI anyway. If you have a long running task, use an async workflow and have it update your model. Keep your model in normal form but set up observers/computed properties in model views. Finally bind views to your model views.
Then your flow is:
- user performs a UI action like clicking on a button,
- button is bound to a field in the model view, which gets a onClick callback
- onClick dispatches the async workflow
- UI thread continues so the user can do other stuff if needed
- async workflow dispatcher picks up the task and starts executing it
- as it progresses, the w/f may update the model or it could update the model only at the end
- when the model updates, observers are notified and recompute their output
- view model updates the view properties that changed
- view refreshes

Consider your modern car, when you press on the gas pedal (UI) you send a signal (dispatch) to the on board computer (model). The later decides how much gas it should send to the engine (model logic). A bunch of sensors read your speed, rpm, etc. (view model) and they turn these values into something that the dashboard displays (view)

Old cars would directly couple the gas pedal with the carburetor and the dashboard have gauges directly hooked to the wheels and engine. It is a far simpler design but it doesn't allow for much 'smartness'.
WarSame
Profile Blog Joined February 2010
Canada1950 Posts
May 16 2018 01:05 GMT
#19166
Ah, right. I can't implement the Observer pattern for my DB because I'm using GreenDAO which doesn't support it. Your idea sounds great, though.
Can it be I stayed away too long? Did you miss these rhymes while I was gone?
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2018-05-16 07:35:34
May 16 2018 07:18 GMT
#19167
Of course you can implement the Observer pattern, just write a class that gates access to the ORM.


Use one Activity. Up to you about whether you want lots of Fragments or not. Don't use AsyncTask or Loaders or Handlers. Use LiveData which is part of the new Architecture Components.

Here's a bunch of modern samples.

https://github.com/googlesamples/android-architecture-components
https://developer.android.com/topic/libraries/architecture/



For fun watch about more modern Android development:

There is no one like you in the universe.
berated-
Profile Blog Joined February 2007
United States1134 Posts
May 16 2018 10:41 GMT
#19168
On May 16 2018 16:18 Blisse wrote:
Of course you can implement the Observer pattern, just write a class that gates access to the ORM.


Use one Activity. Up to you about whether you want lots of Fragments or not. Don't use AsyncTask or Loaders or Handlers. Use LiveData which is part of the new Architecture Components.

Here's a bunch of modern samples.

https://github.com/googlesamples/android-architecture-components
https://developer.android.com/topic/libraries/architecture/



For fun watch about more modern Android development:

https://www.youtube.com/watch?v=IrMw7MEgADk


When did all this stuff come out? I just skimmed it but it looks way nicer than the previous apis. We abandoned the Android part after about a year of iterating to loaders for everything if you don't want your app to a crash and just use a webview wrapper for everything. Does the new architecture help handle network failures more easily too?
Manit0u
Profile Blog Joined August 2004
Poland17776 Posts
May 17 2018 18:28 GMT
#19169
[image loading]
Time is precious. Waste it wisely.
Khalum
Profile Joined September 2010
Austria831 Posts
May 17 2018 19:57 GMT
#19170
On May 18 2018 03:28 Manit0u wrote:
[image loading]


Seems rhobust.
WarSame
Profile Blog Joined February 2010
Canada1950 Posts
May 17 2018 23:30 GMT
#19171
On May 16 2018 16:18 Blisse wrote:
Of course you can implement the Observer pattern, just write a class that gates access to the ORM.


Use one Activity. Up to you about whether you want lots of Fragments or not. Don't use AsyncTask or Loaders or Handlers. Use LiveData which is part of the new Architecture Components.

Here's a bunch of modern samples.

https://github.com/googlesamples/android-architecture-components
https://developer.android.com/topic/libraries/architecture/



For fun watch about more modern Android development:

https://www.youtube.com/watch?v=IrMw7MEgADk

Well, also because I don't think it applies to part of my use case. Generating a wallet file takes ~5s, which may be too long for a user to wait on an activity to get the updated data. However, I will do it because it seems better.
Can it be I stayed away too long? Did you miss these rhymes while I was gone?
Hanh
Profile Joined June 2016
146 Posts
May 18 2018 00:07 GMT
#19172
On May 18 2018 08:30 WarSame wrote:
Show nested quote +
On May 16 2018 16:18 Blisse wrote:
Of course you can implement the Observer pattern, just write a class that gates access to the ORM.


Use one Activity. Up to you about whether you want lots of Fragments or not. Don't use AsyncTask or Loaders or Handlers. Use LiveData which is part of the new Architecture Components.

Here's a bunch of modern samples.

https://github.com/googlesamples/android-architecture-components
https://developer.android.com/topic/libraries/architecture/



For fun watch about more modern Android development:

https://www.youtube.com/watch?v=IrMw7MEgADk

Well, also because I don't think it applies to part of my use case. Generating a wallet file takes ~5s, which may be too long for a user to wait on an activity to get the updated data. However, I will do it because it seems better.


The user doesn't wait for anything. As I said, the workflow is async and the user interface is not blocked. If your app supports multiple wallets, he could even create more than one and still not block.
WarSame
Profile Blog Joined February 2010
Canada1950 Posts
May 18 2018 03:57 GMT
#19173
I get that it doesn't block the main thread, I was just thinking that since I have to work with wallets and Ethereum my wait time for certain actions can be ~40s where a notification may serve the purpose better than waiting for the UI. But I'll put both in.
Can it be I stayed away too long? Did you miss these rhymes while I was gone?
enigmaticcam
Profile Blog Joined October 2010
United States280 Posts
Last Edited: 2018-05-18 17:44:04
May 18 2018 17:43 GMT
#19174
Question on entity framework in C#.Net. I know EF supports transactions. But I want my SaveChanges to be dependent on a database check and I'm not sure how to do that.

I have an entity and any user can potentially create a new row in that table. This table has an IsComplete field. I only want to allow creating new rows if all rows in the table are marked true for IsComplete. The default value when creating a new row is false for IsComplete. So obviously there's potential risk if two different people create a new row at the same time. In that scenario, I would only want one to be successful, and the other should fail because the first one is not complete.

Typically I would just wrap the check and the save in a sql transaction script, but I'm not sure how to do that using EF. Any help? I tried googling, but I keep getting more broad information on just transactions or rolling back SaveChanges.
Manit0u
Profile Blog Joined August 2004
Poland17776 Posts
May 18 2018 20:03 GMT
#19175
You could either try locking the database (SELECT FOR UPDATE), a transaction that checks the count at the beginning and end and rolls back if it's not right, or using distributed locking with something like Redis Mutex.
Time is precious. Waste it wisely.
supereddie
Profile Joined March 2011
Netherlands151 Posts
May 19 2018 09:17 GMT
#19176
On May 19 2018 02:43 enigmaticcam wrote:
Question on entity framework in C#.Net. I know EF supports transactions. But I want my SaveChanges to be dependent on a database check and I'm not sure how to do that.

I have an entity and any user can potentially create a new row in that table. This table has an IsComplete field. I only want to allow creating new rows if all rows in the table are marked true for IsComplete. The default value when creating a new row is false for IsComplete. So obviously there's potential risk if two different people create a new row at the same time. In that scenario, I would only want one to be successful, and the other should fail because the first one is not complete.

Typically I would just wrap the check and the save in a sql transaction script, but I'm not sure how to do that using EF. Any help? I tried googling, but I keep getting more broad information on just transactions or rolling back SaveChanges.

Just add a check constraint in the database. It will generate an exception and then you can rollback your transaction.
"Do not try to make difficult things possible, but make simple things simple." - David Platt on Software Design
sabas123
Profile Blog Joined December 2010
Netherlands3122 Posts
May 19 2018 15:43 GMT
#19177
Just got my necessary math certificate after first hearing I failed it. Now I can finally go on to a University and study actual computer science instead of some flaky applied version. I'M SO HAPPY!!!!
The harder it becomes, the more you should focus on the basics.
bo1b
Profile Blog Joined August 2012
Australia12814 Posts
Last Edited: 2018-05-20 02:15:36
May 20 2018 02:15 GMT
#19178
On May 20 2018 00:43 sabas123 wrote:
Just got my necessary math certificate after first hearing I failed it. Now I can finally go on to a University and study actual computer science instead of some flaky applied version. I'M SO HAPPY!!!!

Good shit man Depending on what you want to study in cs, selecting to do more mathematics rather then less can be a truly excellent idea.
ShoCkeyy
Profile Blog Joined July 2008
7815 Posts
May 20 2018 04:16 GMT
#19179
Congrats Sabas123, as bo1b said, going a more math route would be a smart idea. A lot of companies are looking for more stats engineers due to machine learning, and AI which are the two largest growing sectors for CS imo.
Life?
bo1b
Profile Blog Joined August 2012
Australia12814 Posts
May 20 2018 04:38 GMT
#19180
Most of the really specialised subsets of cs (I want to say all, but I could be wrong) have heavy groundings in various types of math.
Prev 1 957 958 959 960 961 1032 Next
Please log in or register to reply.
Live Events Refresh
Kung Fu Cup
11:00
KungFu Cup 2026 Week 13
IntoTheiNu 1106
RotterdaM902
WardiTV776
TKL 301
SteadfastSC165
IndyStarCraft 149
CranKy Ducklings59
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
RotterdaM 902
TKL 301
Ryung 242
SteadfastSC 165
IndyStarCraft 149
ProTech122
SHIN 103
RushiSC 34
trigger 31
StarCraft: Brood War
Britney 34362
Shuttle 2175
Sea 1922
EffOrt 1011
Hyuk 799
Light 738
firebathero 603
Soma 593
Horang2 456
BeSt 433
[ Show more ]
ggaemo 236
Snow 233
hero 175
Rush 167
Soulkey 151
Zeus 142
Last 136
Hyun 87
Dewaltoss 79
Pusan 71
Aegong 45
[sc1f]eonzerg 40
Free 34
sorry 31
ToSsGirL 31
scan(afreeca) 24
Sacsri 16
Shine 15
Bale 14
zelot 12
Rock 1
Dota 2
Gorgc6182
singsing3633
Dendi1085
qojqva942
Fuzer 636
XaKoH 594
XcaliburYe131
420jenkins113
Counter-Strike
x6flipin355
kRYSTAL_34
Super Smash Bros
Mew2King73
Other Games
hiko1179
B2W.Neo1035
FrodaN509
DeMusliM371
crisheroes320
ceh9270
Hui .195
amsayoshi29
KnowMe29
Trikslyr6
Organizations
Dota 2
PGL Dota 2 - Main Stream229
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
[ Show 16 non-featured ]
StarCraft 2
• EnkiAlexander 31
• mYiSmile112
• CranKy Ducklings SOOP9
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• FirePhoenix0
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Nemesis4040
• TFBlade750
Upcoming Events
Replay Cast
9h
CrankTV Team League
20h
Bombastic Starleague
1d 5h
The PondCast
1d 19h
HomeStory Cup
1d 20h
Replay Cast
2 days
HomeStory Cup
2 days
Replay Cast
3 days
HomeStory Cup
3 days
OSC
3 days
[ Show More ]
Sparkling Tuna Cup
4 days
WardiTV Weekly
5 days
The PondCast
6 days
Liquipedia Results

Completed

YSL S3
Douyu Cup 2026
Murky Cup 2026

Ongoing

IPSL Spring 2026
Acropolis #4
CSL Season 21: Qualifier 2
SCTL 2026 Spring
XSE Pro League 2026
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 2026
Asian Champions League 2026
IEM Atlanta 2026
PGL Astana 2026
BLAST Rivals Spring 2026
IEM Rio 2026

Upcoming

CSL 2026 Summer (S21)
ASL Season 22:Wild Card Qualifier
CSLAN 4
Blizzard Classic Cup 2026
Kung Fu Cup 2026 Grand Finals
RSL Revival: Season 6
CranK Gathers Season 4: BW vs SC2 Team League
HSC XXIX
Light Tournament 2026
Eternal Conflict S2 Finale
Heroes Pulsing #3
Eternal Conflict S2 E1
FISSURE Playground #5
BLAST Open Fall 2026
Esports World Cup 2026
BLAST Bounty Summer 2026
BLAST Bounty Summer Qual
Stake Ranked Episode 3
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2026 TLnet. All Rights Reserved.