Resuming Application/Activity after being pushed to backgrou

Put your problem here if it does not fit any of the other categories.

Resuming Application/Activity after being pushed to backgrou

Postby niko86 » Tue Mar 08, 2011 2:35 pm

So i use my application, i press the home button, later i want to resume my application.
It is still running according to the taskmanager, but how do i bring it to the foreground again?
If i drag down the Status Bar there is for example the JuiceDefender Notification, USB connected and stuff.
How do i get my application to show up there so i can resume it?

Is there any common best practice or do i need to just create a notification using NotifcationManager and setLatestEventInfo in the onStop{ } part of the activity?

Thanks
niko86
Freshman
Freshman
 
Posts: 3
Joined: Tue Mar 08, 2011 2:28 pm

Top

Re: Resuming Application/Activity after being pushed to back

Postby raj_J2ME » Wed Mar 09, 2011 7:34 am

niko86 wrote:So i use my application, i press the home button, later i want to resume my application.
It is still running according to the taskmanager, but how do i bring it to the foreground again?


Thanks

That depends upon you that when and on what action you wanna put your activity in the foreground. Like you can put the same when there is some incoming interruption. Intent are the way you can use the put the event to put the Activity in the foreground.

Please check this link,
http://stackoverflow.com/questions/4905599/how-to-bring-an-activity-to-foreground-or-create-if-not-existing
Thanks with Regards,
Raj - The Kernel
raj_J2ME
Master Developer
Master Developer
 
Posts: 311
Joined: Tue Feb 15, 2011 7:40 am
Location: The Capital of India,

Re: Resuming Application/Activity after being pushed to back

Postby niko86 » Wed Mar 09, 2011 8:15 am

Oh, i forgot to update this thread, after some intensive digging i did not find a solution so i took another approach

create notification inside onCreate()
set flags = Notification.FLAG_ONGOING_EVENT;
set setLatestEventInfo

This way the notification stays there regardless what happens to the activity or application.
It appears as "ongoing", so clearing notifications manually does not clear this one.
This seems correct to me as i wanted the notification and icon to symbolize that my app is still running.

to cancel the notification if the user really exits the application:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. //inside your activity:
  2. public boolean onKeyDown(int keyCode, KeyEvent event){
  3.         //get keypresses
  4.         if (keyCode == KeyEvent.KEYCODE_BACK){
  5.                 //intercept keycode_back
  6.                 NotificationManager notificationManager =
  7.                         (NotificationManager)this.getSystemService(Context.NOTIFICATION_SERVICE);
  8.                 notificationManager.cancel(13371337);
  9.                 //get NotificationManager, cancel the notification by id
  10.                 this.finish();
  11.                 //call finish to exit the application
  12.         }
  13.         return true;
  14.     }
  15.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


Now i need to figure out a way to keep the application from getting closed by the system while in background.
niko86
Freshman
Freshman
 
Posts: 3
Joined: Tue Mar 08, 2011 2:28 pm

Re: Resuming Application/Activity after being pushed to back

Postby raj_J2ME » Wed Mar 09, 2011 8:22 am

Now i need to figure out a way to keep the application from getting closed by the system while in background.

Please check this link,
http://android.bigresource.com/Track/android-UwETClPhg/
Thanks with Regards,
Raj - The Kernel
raj_J2ME
Master Developer
Master Developer
 
Posts: 311
Joined: Tue Feb 15, 2011 7:40 am
Location: The Capital of India,

Re: Resuming Application/Activity after being pushed to back

Postby niko86 » Wed Mar 09, 2011 9:38 am

I just came to the conclusion to scrap the whole concept and start over.
A service will be the way to go, i think this is much more efficient than my initial approach.
niko86
Freshman
Freshman
 
Posts: 3
Joined: Tue Mar 08, 2011 2:28 pm

Re: Resuming Application/Activity after being pushed to back

Postby raj_J2ME » Wed Mar 09, 2011 9:55 am

niko86 wrote:I just came to the conclusion to scrap the whole concept and start over.
A service will be the way to go, i think this is much more efficient than my initial approach.

I also think the same after going through the link I posted.
Thanks with Regards,
Raj - The Kernel
raj_J2ME
Master Developer
Master Developer
 
Posts: 311
Joined: Tue Feb 15, 2011 7:40 am
Location: The Capital of India,

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 19 guests