mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-22 01:51:47 +00:00
FindMyPhone: better activity lifecycle handling
Summary: There are some minor problems with current implementation: if device configuration changes (screen orientation, etc.) while the "FindMyPhone" ringtone is playing, the activity gets recreated and starts to play a new ringtone again, but the first ringtone is not stopped. Also if the user leaves the activity the ringtone continues to play, the user has no way to get back to the activity to stop it. With these changes the ringtone starts playing when the activity becomes visible and stops when the activity is being hidden/destroyed. If the user leaves the activity (without destroying it) and then presses "Ring my phone" button again, the activity becomes visible again and starts to play the ringtone. There are other ways to improve it that I did not touch: use a Service to play the ringtone (so not to depend on the activity's lifecycle) or handle configuration changes in activity (so it is not recreated on orientation changes). Test Plan: Activate "Find My Phone" feature and try to turn phone or leave activity. Reviewers: albertvaka Reviewed By: albertvaka Tags: #kde_connect Differential Revision: https://phabricator.kde.org/D4548
This commit is contained in:
parent
c0502803c4
commit
3cc71a69a4
@ -140,6 +140,7 @@
|
||||
<activity
|
||||
android:name="org.kde.kdeconnect.Plugins.FindMyPhonePlugin.FindMyPhoneActivity"
|
||||
android:label="@string/findmyphone_title"
|
||||
android:configChanges="orientation|screenSize"
|
||||
android:excludeFromRecents="true"
|
||||
android:launchMode="singleInstance">
|
||||
</activity>
|
||||
|
@ -21,7 +21,12 @@ public class FindMyPhoneActivity extends Activity {
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
super.onNewIntent(intent);
|
||||
finish(); //If this activity was already open and we received the ring packet again, just finish it
|
||||
|
||||
if(ringtone != null) {
|
||||
// If this activity was already open and we received the ring packet again, just finish it
|
||||
finish();
|
||||
}
|
||||
// otherwise the activity will become active again
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -40,6 +45,11 @@ public class FindMyPhoneActivity extends Activity {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
|
||||
Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
|
||||
ringtone = RingtoneManager.getRingtone(getApplicationContext(), ringtoneUri);
|
||||
@ -61,12 +71,16 @@ public class FindMyPhoneActivity extends Activity {
|
||||
}
|
||||
|
||||
ringtone.play();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finish() {
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
|
||||
if(ringtone != null) {
|
||||
ringtone.stop();
|
||||
super.finish();
|
||||
ringtone = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user