Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
hds
flexin
android-app
Commits
66f45423
Commit
66f45423
authored
Nov 16, 2017
by
Nastuzzi Samy
Browse files
Better restart
parent
763c0382
Changes
2
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/fr/utc/simde/jessy/BaseActivity.java
View file @
66f45423
...
...
@@ -158,6 +158,38 @@ public abstract class BaseActivity extends InternetActivity {
}.
start
();
}
protected
void
restartApp
(
Activity
activity
)
{
try
{
PackageManager
pm
=
getPackageManager
();
//check if we got the PackageManager
if
(
pm
!=
null
)
{
//create the intent with the default start activity for your application
Intent
mStartActivity
=
pm
.
getLaunchIntentForPackage
(
getPackageName
()
);
if
(
mStartActivity
!=
null
)
{
mStartActivity
.
addFlags
(
Intent
.
FLAG_ACTIVITY_CLEAR_TOP
);
//create a pending intent so the application is restarted after System.exit(0) was called.
// We use an AlarmManager to call this intent in 100ms
int
mPendingIntentId
=
223344
;
PendingIntent
mPendingIntent
=
PendingIntent
.
getActivity
(
activity
,
mPendingIntentId
,
mStartActivity
,
PendingIntent
.
FLAG_CANCEL_CURRENT
);
AlarmManager
mgr
=
(
AlarmManager
)
getSystemService
(
Context
.
ALARM_SERVICE
);
mgr
.
set
(
AlarmManager
.
RTC
,
System
.
currentTimeMillis
()
+
100
,
mPendingIntent
);
//kill the application
System
.
exit
(
0
);
}
else
{
Log
.
e
(
LOG_TAG
,
"Was not able to restart application, mStartActivity null"
);
}
}
else
{
Log
.
e
(
LOG_TAG
,
"Was not able to restart application, PM null"
);
}
}
catch
(
Exception
ex
)
{
Log
.
e
(
LOG_TAG
,
"Was not able to restart application"
);
}
}
protected
void
startMainActivity
(
final
Activity
activity
)
{
disconnect
();
...
...
app/src/main/java/fr/utc/simde/jessy/MainActivity.java
View file @
66f45423
...
...
@@ -473,7 +473,7 @@ public class MainActivity extends BaseActivity {
reloadButton
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
start
MainActivity
(
MainActivity
.
this
);
re
start
App
(
MainActivity
.
this
);
}
});
...
...
@@ -481,7 +481,7 @@ public class MainActivity extends BaseActivity {
@Override
public
void
onClick
(
View
v
)
{
config
.
reset
();
start
MainActivity
(
MainActivity
.
this
);
re
start
App
(
MainActivity
.
this
);
}
});
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment