This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlinx.coroutines.channels.produce | |
import kotlinx.coroutines.coroutineScope | |
import kotlinx.coroutines.flow.Flow | |
import kotlinx.coroutines.flow.collect | |
import kotlinx.coroutines.flow.flow | |
import java.util.concurrent.TimeoutException | |
fun <T> Flow<T>.withTimeout(timeoutMillis: Long): Flow<T> { | |
return flow { // New flow to wrap the old one | |
coroutineScope { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyActivity extends Activity { | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
SharedPreferences prefs = Harmony.getSharedPreferences(context, "my_prefs"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyActivity : Activity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
val prefs: SharedPreferences = context.getHarmonySharedPreferences("my_prefs") | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Assume this service has the 'android:process' tag in the AndroidManifest.xml | |
class SimpleService : Service() { | |
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { | |
val sharedPrefs = getSharedPreferences("my_prefs", Context.MODE_PRIVATE) | |
sharedPrefs.edit { putInt("my_counter", sharedPrefs.getInt("my_counter", 0) + 1) } // Simple counter increment | |
return super.onStartCommand(intent, flags, startId) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyActivity : Activity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
val sharedPrefs = getSharedPreferences("my_prefs", Context.MODE_PRIVATE) | |
sharedPrefs.edit { putInt("my_counter", sharedPrefs.getInt("my_counter", 0) + 1) } // Simple counter increment | |
} | |
} |