It doesn't always do it, and if it runs fine the first time, it will run fine the rest of the time. But some devices it just minimizes on first and all attempts to run it. Switching to the process if minimized immediately forces it to minimize again.
Here's my code, its pretty lengthy....
// Project: Sandbox
// Created: 2015-07-08
// set window properties
SetWindowTitle( "Planetside 2: StreakBack" )
SetDisplayAspect(-1) //Forces the app to take the devices native aspect ratio
SetOrientationAllowed(0,0,1,1) //Lock to landscape mode
setwindowsize(1024,768,0)
///////////////////////////////////////////////////////////////
createsprite (3,0) //Set initial background (Animated sprite)
loadimage(8,"1.png")
loadimage(9,"2.png")
loadimage(10,"3.png")
loadimage(11,"4.png")
loadimage(12,"5.png")
loadimage(13,"6.png")
loadimage(14,"7.png")
loadimage(15,"8.png")
loadimage(16,"9.png")
loadimage(17,"10.png")
loadimage(18,"11.png")
loadimage(19,"12.png")
loadimage(20,"13.png")
loadimage(21,"14.png")
loadimage(22,"15.png")
loadimage(23,"16.png")
loadimage(24,"17.png")
loadimage(25,"18.png")
loadimage(26,"19.png")
loadimage(27,"20.png")
loadimage(28,"21.png")
loadimage(29,"22.png")
addspriteanimationframe(3,8)
addspriteanimationframe(3,9)
addspriteanimationframe(3,10)
addspriteanimationframe(3,11)
addspriteanimationframe(3,12)
addspriteanimationframe(3,13)
addspriteanimationframe(3,14)
addspriteanimationframe(3,15)
addspriteanimationframe(3,16)
addspriteanimationframe(3,17)
addspriteanimationframe(3,18)
addspriteanimationframe(3,19)
addspriteanimationframe(3,20)
addspriteanimationframe(3,21)
addspriteanimationframe(3,22)
addspriteanimationframe(3,23)
addspriteanimationframe(3,24)
addspriteanimationframe(3,25)
addspriteanimationframe(3,26)
addspriteanimationframe(3,27)
addspriteanimationframe(3,28)
addspriteanimationframe(3,29)
setspritesize(3,128,125) //Scale/Stretch the background to fit entire app
setspriteposition(3,-14,-13) //Align sprite with screen constraints
setspritecolorred(3,100) //Dim the sprite for better contrast to the white stat text
SetSpriteColorGreen(3,100)
SetSpriteColorBlue(3,100)
SetSpriteDepth(3,10) //Bring sprite to the foreground
playsprite(3) //Play our animated sprite background
loadimage(2,"font.png") //Pre load custom font
loadimage(3,"button_up.png") //Pre load edit button's "UP" image
loadimage(4,"button_dn.png") //Pre load edit button's "DOWN" image
loadimage(5,"button_up2.png") //Pre load background toggle button's "UP" image
loadimage(6,"button_dn2.png") //Pre load background toggle button's "DOWN" image
loadimage(31,"button_up3.png") //Pre load voice pack button's "UP" image
loadimage(32,"button_dn3.png") //Pre load voice pack button's "DOWN" image
loadimage(33,"button_up4.png") //Pre exit button's "UP" image
loadimage(34,"button_dn4.png") //Pre exit button's "DOWN" image
loadimage(7,"flash.png") //Pre load the image that will be our kill/death "flash"
createsprite(1,7) //Create sprite that will be white flash
setspritesize(1,100,100) //Set the flash sprite to full screen
createsprite(2,7) //Create sprite that will be red flash
setspritesize(2,100,100) //Set the flash sprite to full screen
setspritecoloralpha(1,15) //Set white flash to almost fully transparent
setspritecoloralpha(2,15) //Set red flash to almost fully transparent
loadimage(30,"badconn.png") //Pre load icon for connection issues
SetTextDefaultFontImage(2) //Set our font image as the app's font source
createtext(1,"") //Create our text string, which will display all text feedback in one string value
settextsize(1,9)
SetTextPosition(1,1,4) //Set the text size of our text string
createtext(2,"Voice Pack: Killography") //This text will display the currently selected voice pack
settextsize(2,4) //Set text size for voice pack readout
SetTextPosition(2,16,5.5)
MyTimer#=0 //Our variable to act as a counter
MainLoop() //Call the main function (Let's start the show!)
function MainLoop()
charid$ = "" //Create our character ID holder
AddVirtualButton(1,4,7,7) //Change name button
setvirtualbuttonimagedown(1,4)
setvirtualbuttonimageup(1,3)
//AddVirtualButton(2,12,7,7) //black screen button
//setvirtualbuttonimagedown(2,6)
//setvirtualbuttonimageup(2,5)
//SetVirtualButtonActive(2,0) //disable blackscreen button (until it is working properly)
AddVirtualButton(3,12,7,7) //Voice pack change button
setvirtualbuttonimagedown(3,32)
setvirtualbuttonimageup(3,31)
AddVirtualButton(4,96,7,7) //Exit Button
setvirtualbuttonimagedown(4,34)
setvirtualbuttonimageup(4,33)
NOWTIME#=valfloat(GetFromWeb("djmc.ca","timenow.php")) //Get current UNIX timestamp for future calculations
BGVAR#=0 //Used to let us know if the background image is off or on
Streak#=0 //DECLARE VARIABLES TO HOUSE STAT CHECKS
BestStreak#=0
PrevKill$="0"
PrevDeath$="0"
NewKill$="0"
NewDeath$="0"
SessionKills#=0
SessionDeaths#=0
VoicePack$="Killography"
//loadsound(32,"button.wav") //Button tick sound
loadsound(2,"snd\Killography\1.wav") //Kill sounds for Killography
loadsound(3,"snd\Killography\2.wav")
loadsound(4,"snd\Killography\3.wav")
loadsound(5,"snd\Killography\4.wav")
loadsound(6,"snd\Killography\5.wav")
loadsound(7,"snd\Killography\6.wav")
loadsound(8,"snd\Killography\7.wav")
loadsound(9,"snd\Killography\8.wav")
loadsound(11,"snd\Killography\9.wav")
loadsound(11,"snd\Killography\10.wav")
loadsound(12,"snd\Killography\11.wav")
loadsound(13,"snd\Killography\12.wav")
loadsound(14,"snd\Killography\13.wav")
loadsound(15,"snd\Killography\d1.wav") //Death sounds for Killography
loadsound(16,"snd\Killography\d2.wav")
loadsound(17,"snd\ShaunOfTheDead\1.wav") //Kill sounds for ShaunOfTheDead
loadsound(18,"snd\ShaunOfTheDead\2.wav")
loadsound(19,"snd\ShaunOfTheDead\3.wav")
loadsound(20,"snd\ShaunOfTheDead\4.wav")
loadsound(21,"snd\ShaunOfTheDead\5.wav")
loadsound(22,"snd\ShaunOfTheDead\6.wav")
loadsound(23,"snd\ShaunOfTheDead\7.wav")
loadsound(24,"snd\ShaunOfTheDead\8.wav")
loadsound(25,"snd\ShaunOfTheDead\9.wav")
loadsound(26,"snd\ShaunOfTheDead\10.wav")
loadsound(27,"snd\ShaunOfTheDead\11.wav")
loadsound(28,"snd\ShaunOfTheDead\12.wav")
loadsound(29,"snd\ShaunOfTheDead\13.wav")
loadsound(30,"snd\ShaunOfTheDead\d1.wav") //Death sounds for ShaunOfTheDead
loadsound(31,"snd\ShaunOfTheDead\d2.wav")
loadsound(33,"snd\DongTang\1.wav") //Kill sounds for Dong Tang
loadsound(34,"snd\DongTang\2.wav")
loadsound(35,"snd\DongTang\3.wav")
loadsound(36,"snd\DongTang\4.wav")
loadsound(37,"snd\DongTang\5.wav")
loadsound(38,"snd\DongTang\6.wav")
loadsound(39,"snd\DongTang\7.wav")
loadsound(40,"snd\DongTang\8.wav")
loadsound(41,"snd\DongTang\9.wav")
loadsound(42,"snd\DongTang\10.wav")
loadsound(43,"snd\DongTang\11.wav")
loadsound(44,"snd\DongTang\12.wav")
loadsound(45,"snd\DongTang\13.wav")
loadsound(46,"snd\DongTang\d1.wav") //Death sounds for Dong Tang
loadsound(47,"snd\DongTang\d2.wav")
loadsound(48,"snd\Kiwo\1.wav") //Kill sounds for Kiwo
loadsound(49,"snd\Kiwo\2.wav")
loadsound(50,"snd\Kiwo\3.wav")
loadsound(51,"snd\Kiwo\4.wav")
loadsound(52,"snd\Kiwo\5.wav")
loadsound(53,"snd\Kiwo\6.wav")
loadsound(54,"snd\Kiwo\7.wav")
loadsound(55,"snd\Kiwo\8.wav")
loadsound(56,"snd\Kiwo\9.wav")
loadsound(57,"snd\Kiwo\10.wav")
loadsound(58,"snd\Kiwo\11.wav")
loadsound(59,"snd\Kiwo\12.wav")
loadsound(60,"snd\Kiwo\13.wav")
loadsound(61,"snd\Kiwo\d1.wav") //Death sounds for Kiwo
loadsound(62,"snd\Kiwo\d2.wav")
opentoread(1,"IGN.txt") //Load prefered player name (If exists...)
IGN$ = readstring(1)
closefile(1)
if IGN$ = "" //If no player name has been configured, prompt to enter one.
input("Enter in-game name",30)
endif
CharID$=(GetFromWeb("djmc.ca","charid.php?name=" + IGN$)) //Turn that player name into a character ID, for querying SOE API
//End
do
// playsound(43,75,0)
SPRAlpha#=GetSpriteColorAlpha(1) //Set our flash sprite alpha variables
SPRAlpha2#=GetSpriteColorAlpha(2)
if getvirtualbuttonpressed(3)=1 //If voice pack button pressed, cycle to next voice pack
if VoicePack$="Killography"
voicepack$="ShaunOfTheDead"
settextstring(2,"Voice Pack: Shaun of the Dead")
playsound(random(17,31),100,0)
elseif VoicePack$="ShaunOfTheDead"
voicepack$="DongTang"
settextstring(2,"Voice Pack: Dong Tang")
playsound(random(33,47),100,0)
elseif VoicePack$="DongTang"
voicepack$="Kiwo"
settextstring(2,"Voice Pack: Kiwo")
playsound(random(48,62),100,0)
elseif VoicePack$="Kiwo"
voicepack$="Killography"
settextstring(2,"Voice Pack: Killography")
playsound(random(2,16),100,0)
endif
//mainloop()
endif
if getvirtualbuttonpressed(1)=1 //If edit button pressed, prompt to enter a new player name
playsound(32,100,0)
input("Enter in-game name",30)
mainloop()
endif
if getvirtualbuttonpressed(4)=1 //If exit button pressed, exit app
exit
endif
//if getvirtualbuttonpressed(2)=1 //If background button pressed, turn off bg image, unless its already off, in which case turn it on.
// if bgvar#=0
// SetSpriteDepth(3,10) //Bring our animated bg to the foreground
// setspritedepth(backdrop,10000) //Send black bg to the background (not visible)
// PlaySprite(3) //Animate bg
// bgvar#=1 //Store variable to later let us know if the BG is black or animated
//else
// SetSpriteDepth(3,10000) //Send animated bg to the background (not visible)
// stopsprite(3) //Stop playback of the animated bg
// setspritedepth(backdrop,10) //Bring black bg to the foreground
// backdrop = CreateSprite ( LoadImage ( "bbg.jpg" ) ) //Load black bg image
// SetSpriteSize ( backdrop, 100, 100 ) //Set it to full screen
// bgvar#=0 //Store variable to later let us know if the BG is black or animated
// endif
// playsound(32,100,0)
// endif
if(MyTimer#=0) //TIMER TICK!
NewDeath$=(GetFromWeb("djmc.ca","death.php?charid=" + CharID$)) //PHP WAS USED TO AVOID ATTEMPTING JSON PARSING IN AGK2
NewKill$=(GetFromWeb("djmc.ca","kill.php?charid=" + CharID$ + "&prevdeath=" + newdeath$)) //THESE PHP DOCUMENTS ONLY RETURN THE TIMESTAMP OF MOST RECENT KILL/DEATH EVENTS
//FOR NOW THEY ONLY RETURN A TEST PLAYERS STATS, UPON RELEASE THEY WILL BE CALLED DYNAMICALLY
//EXAMPLE: DJMC.CA/KILL.PHP?CHARID=[characterid]&prevdeath=[timestampofpreviousdeath]
//Returns current streak to a max of 1000
//EXAMPLE: DJMC.CA/DEATH.PHP?CHARID=[characterid] //Returns timestamp of last death
//playsound(13,100,0)
mytimer#=300 //FORCES THE QUERY INTERVAL TO ROUGHLY 3 SECONDS, AS DAYBREAKGAMES API ONLY ALLOWS 10 QUERIES PER MINUTE
//WHICH WORKS OUT TO EVERY 6 SECONDS, BUT I LIVE ON THE EDGE...
endif
if NewKill$=PrevKill$ //IF NO ADDITIONAL KILL
//DO NOTHING
else //IF GOT ANOTHER KILL
setspritecoloralpha(1,255) //Make white flash fully opaque
inc sessionkills#,1 //Add to total session kills
streak# = valfloat(newkill$)
if streak#>(streak#+30)
exitfunction
endif //Store latest kill timestamp
if streak# > beststreak# //If current streak total exceeds best session streak total
beststreak#=streak# //Update best streak
endif
if streak# > 13 //IF STREAK EXCEEDS NUMBER OF SOUNDS
if voicepack$="Killography"
playsound(random(2,14),100,0) //PLAY RANDOM SOUND
endif
if voicepack$="ShaunOfTheDead"
playsound(random(17,31),100,0) //PLAY RANDOM SOUND
endif
if voicepack$="DongTang"
playsound(random(42,45),100,0) //PLAY RANDOM SOUND
endif
if voicepack$="Kiwo"
playsound(random(48,60),100,0) //PLAY RANDOM SOUND
endif
else //OTHERWISE
if voicepack$="Killography"
playsound(Streak#+1,100,0) //PLAY INCREMENTAL SOUND, AS EXPECTED
endif
if voicepack$="ShaunOfTheDead"
playsound(Streak#+16,100,0)
endif
if voicepack$="DongTang"
playsound(Streak#+32,100,0)
endif
if voicepack$="Kiwo"
playsound(Streak#+47,100,0)
endif
endif
endif
if NewDeath$=PrevDeath$ //IF STILL ON KILLSTREAK
//DO NOTHING
ELSE //IF DIED
IF len(newdeath$) < len(prevdeath$)
exitfunction
endif
if valfloat(NewDeath$) < nowtime# //IF DEATH TIMESTAMP IS OLD (AS IN FROM PREVIOUS SESSION)
//DO NOTHING
else //OTHERWISE
inc SessionDeaths#,1 //COUNT THE DEATH
if voicepack$="Killography"
playsound(random(15,16),100,0) //BERATE USER
endif
if voicepack$="ShaunOfTheDead"
playsound(random(30,31),100,0) //BERATE USEr
endif
if voicepack$="DongTang"
playsound(random(46,47),100,0) //BERATE USEr
endif
if voicepack$="Kiwo"
playsound(random(61,62),100,0) //BERATE USEr
endif
Streak#=0 //RESET STREAK
setspritecoloralpha(2,255) //Make red flash fully opaque
SetSpriteColorRed(2,255) //Set color of flash to fully red
SetSpriteColorblue(2,0)
SetSpriteColorgreen(2,0)
endif
endif
opentoread(1,"IGN.txt") //Check IGN again
IGN$ = readstring(1)
closefile(1)
//Print current stats
settextstring(1,(chr(10) + "NAME: " + IGN$ + chr(10) + "STREAK: " +str(Streak#,0) + chr(10) + "BEST STREAK : " + str(beststreak#,0) + chr(10) + chr(10) + "Session Kills: " +str(SessionKills#,0) + chr(10) + "Session Deaths: " +str(SessionDeaths#,0) + chr(10) + "K/D Ratio: " +str(SessionKills#/SessionDeaths#,1)))
PrevKill$=NewKill$ //UPDATE VARS FOR NEXT LOOP
PrevDeath$=NewDeath$
//END DO STUFF
dec mytimer#,1 //COUNTDOWN ONCE
if getspritecoloralpha(1) > 0 //Fade out our flash sprites
dec spralpha#,15 //Decrease our stored alpha value for white flash
SetSpriteColorAlpha(1,spralpha#) //Decrease alpha value of the actual sprite
endif
if getspritecoloralpha(2) > 0
dec spralpha2#,15 //Decrease our stored alpha value for red flash
SetSpriteColorAlpha(2,spralpha2#) //Decrease alpha value of the actual sprite
endif
Sync() //UPDATE SCREEN
loop
endfunction
function GetFromWeb(Host$,URLPath$) //GET BODY STRING FROM DYNAMIC WEB DOCUMENT
Response$=""
if GetInternetState()=1
iHTTP=CreateHTTPConnection()
iSecure=0
szUser$=""
szPass$=""
if SetHTTPHost( iHTTP, Host$, iSecure, szUser$, szPass$ )=1
if SendHTTPRequestASync( iHTTP, URLPath$ )=1
do
ret=GetHTTPResponseReady( iHTTP )
if ret=-1 then exit //Cancel
if ret=1 then exit //Ready
//print("wait ...")
sync()
loop
if ret=1
Response$=GetHTTPResponse( iHTTP )
endif
endif //Get
CloseHTTPConnection( iHTTP )
endif //Host
DeleteHTTPConnection( iHTTP )
endif //Internet
endfunction Response$
Function Input(textin$,length)
SetCursorBlinkTime(0.5)
SetTextInputMaxChars(length)
StartTextInput(textin$)
do
sync()
state=GetTextInputState()
c=GetLastChar()
if GetTextInputCompleted()
if GetTextInputCancelled()
text$=textin$
exit
else
text$=GetTextInput()
IGN$=text$
OpenToWrite ( 1, "IGN.txt", 0 )
WriteString ( 1, text$ )
CloseFile ( 1 )
exit
endif
endif
loop
StopTextInput()
sync()
endfunction text$
-Writing programs for years, new to AGK2