bring up my application WDM 18

Startbeitrag von Tobias am 27.06.2015 22:48

I have an application where a persistent thread shot and generates a notification when a new event arrives. All this does it very well.

I need that shot when the notification prompted the application is in the background and to the foreground so that the user sees.

I have this procedure but has errors

public void startNewActivity(Context context, String packageName) {
Intent intent = context.getPackageManager().getLaunchIntentForPackage(packageName);
if (intent != null) {
// We found the activity now start the activity
} else {
// Bring user to the market or let them choose an app?
intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://details?id=" + packageName));

Thanks for your help



I'm not sure it is perfect, but this does work correctly for my Android application

public static void JBringAppToFront()
try {
// Retrieve the current activity
Activity tmpActivity = getCurrentActivity();

// Retrieve the current Context
Context tmpContext = getApplicationContext();

// Get Class name
String packageName = tmpContext.getPackageName();
Intent launchIntent = tmpContext.getPackageManager().getLaunchIntentForPackage(packageName);
String className = launchIntent.getComponent().getClassName();

// Create intent / activity
Intent myIntent = new Intent();
myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // You need this if starting the activity from a service

// Start the activity
catch(Exception e) {

If you want to show your application on top of the lockscreen so the user can directly see what is happening you can set some extra flags in the initialization code of that window.

public static boolean SetExtraWindowFlags()
// Set Some Extra Window Flags
Activity tmpActivity = getCurrentActivity();

return true;

And when you call this code it will wake your device, turn the screen on and show your application fullscreen

public static boolean JWakeDevice(boolean bWakeup)
// Wake or rest the device
try {

if (bWakeup) {
//callWLProcedure("ShowMessage","Wake UP");
// Awake the Device
Activity tmpActivity = getCurrentActivity();
tmpActivity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_FULLSCREEN);
else {
// Reset stuff
Activity tmpActivity = getCurrentActivity();
tmpActivity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_FULLSCREEN);
} catch(Exception e) {
return false;

return true;

Hope this code helps !

If you apply any improvements, please let me know what you have done to make these functions any better ! ;)

You will have to include the correct import statements before it will compile.

Have a nice day

von Danny Lauwers - am 29.06.2015 15:07
Danny thank you very much

It is just what was wanted, everything worked perfectly.

Thanks Danny

Tobias :spos::)

von Tobias - am 06.07.2015 00:06
Zur Information: hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.