EzDevInfo.com

resume

my personal resume built in HTML/CSS Louisa Barrett

How to make notification intent resume rather than making a new intent?

What i have here is a simple webview activity that when loaded it auto displays an ongoing notification. The idea is that people can navigate away from this activity and quickly access it again from any screen they want by pulling down the drop down menu and selecting it. Then when they want they can just close the notification by hitting the menu button and hitting exit and then the notification clears. This all works fine. However, when the notification is pressed it starts a new instance of the activity. What would i have to change to make it see if the activity has not already been destroyed and i can just call that instance back(resume it) and therefore not needing to load it again and won't need to add another activity to my stack. Any ideas? Any help would be greatly appreciated.

package com.my.app;

import com.flurry.android.FlurryAgent;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent; 
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.webkit.CookieSyncManager;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;

public class Chat extends Activity { 
    private ProgressDialog progressBar;
    public WebView webview;
    private static final String TAG = "Main";

    private NotificationManager mNotificationManager;
    private int SIMPLE_NOTFICATION_ID;

    @Override
    public void onStart() {
       super.onStart();
       CookieSyncManager.getInstance().sync();
       FlurryAgent.onStartSession(this, "H9QGMRC46IPXB43GYWU1");
    }

    public void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState);
        setContentView(R.layout.chat);

        mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);

        final Notification notifyDetails = new Notification(R.drawable.chat_notification,"Chat Started",System.currentTimeMillis());

        notifyDetails.flags |= Notification.FLAG_ONGOING_EVENT;

        Context context = getApplicationContext();

        CharSequence contentTitle = "Chat";
        CharSequence contentText = "Press to return to chat";

        Intent notifyIntent = new Intent(context, Chat.class);

        PendingIntent intent =
        PendingIntent.getActivity(Chat.this, 0,
        notifyIntent, android.content.Intent.FLAG_ACTIVITY_NEW_TASK);
        notifyDetails.setLatestEventInfo(context, contentTitle, contentText, intent);

        mNotificationManager.notify(SIMPLE_NOTFICATION_ID, notifyDetails);

        CookieSyncManager.createInstance(this);
        CookieSyncManager.getInstance().startSync();
        webview = (WebView) findViewById(R.id.webviewchat);
        webview.setWebViewClient(new chatClient());
        webview.getSettings().setJavaScriptEnabled(true);
        webview.getSettings().setPluginsEnabled(true);
        webview.loadUrl("http://google.com");

        progressBar = ProgressDialog.show(Chat.this, "", "Loading Chat...");  
    }

    private class chatClient extends WebViewClient { 
        @Override 
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            Log.i(TAG, "Processing webview url click...");
            view.loadUrl(url);
            return true;
        }

        public void onPageFinished(WebView view, String url) {
            Log.i(TAG, "Finished loading URL: " +url);
            if (progressBar.isShowing()) {
                progressBar.dismiss();
            }
        }
    }

    public boolean onKeyDown(int keyCode, KeyEvent event) { 
        if ((keyCode == KeyEvent.KEYCODE_BACK) && webview.canGoBack()) { 
            webview.goBack(); 
            return true; 
        }
        return super.onKeyDown(keyCode, event); 
    }

    @Override
    public boolean onCreateOptionsMenu (Menu menu) {
        super.onCreateOptionsMenu(menu);
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.chatmenu, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected (MenuItem item) {
        switch (item.getItemId()) {
            case R.id.home:
                Intent a = new Intent(this, Home.class);
                startActivity(a);
                return true;
            case R.id.closechat:
                mNotificationManager.cancel(SIMPLE_NOTFICATION_ID);
                Intent v = new Intent(this, Home.class);
                startActivity(v);
                return true;
        }
        return false;
    }

    public void onStop() {
       super.onStop();
       CookieSyncManager.getInstance().sync();
       FlurryAgent.onEndSession(this);
    }
}

@Commonsware

Just to be sure i have it correct, is this what you were suggesting?

I was a little worried about this line,

PendingIntent.getActivity(Chat.this, 0, notifyIntent, SIMPLE_NOTFICATION_ID);

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState);
    setContentView(R.layout.chat);

    mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);

    final Notification notifyDetails = new Notification(R.drawable.chat_notification,"Chat Started",System.currentTimeMillis());

    notifyDetails.flags |= Notification.FLAG_ONGOING_EVENT;


    Context context = getApplicationContext();

    CharSequence contentTitle = "Chat";
    CharSequence contentText = "Press to return to chat";

    Intent notifyIntent = new Intent(context, Chat.class);

    PendingIntent intent =
    PendingIntent.getActivity(Chat.this, 0, notifyIntent, SIMPLE_NOTFICATION_ID);
    notifyDetails.setLatestEventInfo(context, contentTitle, contentText, intent);
    notifyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

    mNotificationManager.notify(SIMPLE_NOTFICATION_ID, notifyDetails);


    CookieSyncManager.createInstance(this);
    CookieSyncManager.getInstance().startSync();
    webview = (WebView) findViewById(R.id.webviewchat);
    webview.setWebViewClient(new chatClient());
    webview.getSettings().setJavaScriptEnabled(true);
    webview.getSettings().setPluginsEnabled(true);
    webview.loadUrl("http://google.com");

    progressBar = ProgressDialog.show(Chat.this, "", "Loading Chat...");        
}

Source: (StackOverflow)

How to resume a broken upload in HTML5

I am trying to add resume functionality to html5 file uploader.

I need to be able to resume after browser was closed (and reopened) and I lost the file object, I do not want the user to drag/open the file again.

Until now I used java applet to do it but I was hoping to find an html5 solution for this problem.

I thought about saving the files in local storage but they are too big.

Is there a way to save only the file object the path or any other information that might help me reopen the file without asking the user to reopen the file?


Source: (StackOverflow)

Advertisements

Android - restore last viewed Activity

I have 3 different Activities that user navigates between in no particular order. My goal it twofold:

  1. When user switches to something else when app is resumed I want to start where user left even if app was terminated
  2. When last activity is resumed I want to restore it to the last viewed state (this one I think I have a pretty good idea on how to achive)

I think the problem is not start/stop - where I pretty much get what I need, but onCreate() if app was terminated. In that case - it picks Activity that I configured in the manifest. I suppose I can put something in onCreate method of that default activity but is there a better way that I'm maybe missing?


Source: (StackOverflow)

Delphi thread that waits for data, processes it, then resumes waiting

I need to create a thread in Delphi with the following characteristics:

  • Waits until the main thread adds data to a shared queue.
  • Processes all the data in the queue, returning the results to main thread (for this last part I'll just send messages to the main window). Processing is time-consuming, so new data may be added to the queue while the worker thread is processing previous entries.
  • Resumes waiting, using as little cpu cycles as possible.

I cannot send messages to the thread, since it does not have a window handle.

Should I be using some variant of WaitForObject? If so, what would the wait be for? If not, then how can I keep the thread waiting, then awake it when new data comes down the queue?

I've read Multithreading - The Delphi Way, which doesn't seem to answer my question. Perhaps OmniThreadLibrary can do what I need; I can't tell since there's little documentation. I don't know enough about threads in general to figure out if the library will help here and how to use it (or even why to use it instead of just working with TThread descendants).


Source: (StackOverflow)

How to implement pause/resume in cocos2d game?

My question is to look for design solution for pause/resume states (including all data info, which need save ) during cocos2d game.

Including following cases, but not limited:

1). User choose quit, then pop out one dialog for user to choose " quit directly", " pause " ;

2). Someone call in , pop out dialog for user to choose "quit " or " pause " game.

If choose "pause", everything which deserve saving, should be saved. Just like PC games do.

I know Director provides "pause" , "resume " , is that okay for this task ?

Thanks for anyone clues or comments.

Welcome for further discussing via email : apple.dev.sh@gmail.com


Source: (StackOverflow)

Jersey REST support resume/media streaming

I need to support resume on Jersey REST, I'm trying to do it this way:

@Path("/helloworld")
public class RestServer {

@GET

@Path("say")
@Produces("audio/mp3")
public Response getMessage(@HeaderParam("Range") String r ) throws IOException{
    String str="/Users/dima/Music/crazy_town_-_butterfly.mp3";

    System.out.println(r);
    RandomAccessFile f=new RandomAccessFile(str, "r");

    int off=0;
    int to=(int)f.length();
    byte[] data ;
    if(r!=null){
        String from=r.split("=")[1].split("-")[0];
        String t=r.split("=")[1].split("-")[1];
        off=Integer.parseInt(from);
        to=Integer.parseInt(t);

    }
    data= new byte[to-off];
    f.readFully(data, off, to-off);

    ResponseBuilder res=Response.ok(data)
            .header("Accept-Ranges","bytes")
            .header("Content-Range:", "bytes "+off+"-"+to+"/"+data.length)
            .header("Pragma", "no-cache");;

            if(r==null){
                res=res.header("Content-Length", data.length);
            }
            f.close();

            Response ans=res.build();

            return ans;


}
}

I want to be able stream mp3 so the browser can seek the music, but in safari it still not working. any ideas?


Source: (StackOverflow)

Self Suspending a thread in Delphi when it's not needed and safely resuming

This question involves Delphi and XE specifically deprecating Suspend and Resume. I have read other posts and I have not found a similar usage so far, so I’m going to go ahead and ask for a discussion.

What I’d like to know is there a better way to pause a thread when it is not needed?

We have a Delphi class that we have used for years that is basically a FIFO Queue that is associated with a threaded process. The queue accepts a data object on the main thread and if the thread is suspended it will resume it.

As part of the thread’s Execute process the object is popped out of the queue and processed on the thread. Usually this is to do a database lookup.

At the end of the process a property of the object is updated and marked as available to the main thread or passed on to another queue. The last (well it really is the first) step of the Execute process is to check if there are any more items in the queue. If there is it continues, otherwise it suspends itself.

They key is the only suspend action is inside the Execute loop when it is completed, and the only resume during normal operations is called when a new item is placed in the queue. The exception is when the queue class is being terminated.

The resume function looks something like this.

process TthrdQueue.MyResume();
  begin
    if Suspended then begin
      Sleep(1); //Allow thread to suspend if it is in the process of suspending
      Resume();
    end;
  end;

The execute looks similar to this

process TthrdQueue.Execute();
  var
    Obj : TMyObject;
  begin
    inherited;
    FreeOnTerminate := true;
    while not terminated do begin
      if not Queue.Empty then begin
        Obj :=  Pop();
        MyProcess(Obj);  //Do work
        Obj.Ready := true;
      end
      else
        Suspend();  // No more Work
    end;   //Queue clean up in Destructor
  end;  

The TthrdQueue Push routine calls MyResume after adding another object in the stack. MyResume only calls Resume if the thread is suspended.

When shutting down we set terminate to true and call MyResume if it is suspended.


Source: (StackOverflow)

Resuming Application on Android with Unity

I'm trying to implement Pausing in Unity by using OnApplicationPause function.

It seems to work fine when I exit my game (on Android) by pressing home button and then comeback through list of active apps, but when I press the game icon on home screen, it restart the game instead of bringing me back.

Is there any way around this ?


Source: (StackOverflow)

How to Suspend and Resume Threads in android?

I just noticed that suspend and resume in android thraeding has been deprecated. what is the work around for this or how can I suspend and resume a thread in android?

any help would be much appreciated.

Thanks


Source: (StackOverflow)

How to pause and resume CSS3 animation using JavaScript?

I've tried to google and look from this forum a solution for my problem but no luck so far. I would like to pause my CSS3 animation (image slide show) by clicking a picture and also resume to the same animation by clicking a picture.

I know how to pause the slide show and I was also able to resume it once, but then it stops working if try to pause and resume more than one time. Here is how my code looks like:

<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
.pic {
    position: absolute;
    opacity: 0;
}
#pic1 {
    -webkit-animation: pic1 4s infinite linear;
}
#pic2 {
    -webkit-animation: pic2 4s infinite linear;
}
@-webkit-keyframes pic1 {
    0%   {opacity: 0;}
    5%   {opacity: 1;}
    45%  {opacity: 1;}
    50%  {opacity: 0;}
    100% {opacity: 0;}
}
@-webkit-keyframes pic2 {
    0%   {opacity: 0;}
    50%  {opacity: 0;}
    55%  {opacity: 1;}
    95%  {opacity: 1;}
    100% {opacity: 0;}
}
</style>
<script type="text/javascript">
function doStuff(){
    var pic1 = document.getElementById("pic1");
    var pic2 = document.getElementById("pic2");

    pic1.style.webkitAnimationPlayState="paused";
    pic2.style.webkitAnimationPlayState="paused";

    pic1.onclick = function(){
        pic1.style.webkitAnimationPlayState="running";
        pic2.style.webkitAnimationPlayState="running";
    }

    pic2.onclick = function(){
        pic1.style.webkitAnimationPlayState="running";
        pic2.style.webkitAnimationPlayState="running";
    }
}
</script>
</head>  
<body>
    <img id="pic1" class="pic" src="photo1.jpg" />
    <img id="pic2" class="pic" src="photo2.jpg" onclick="doStuff()" />
</body>                                                                 
</html>

I don't want to use any JS libraries (e.g. jQuery) or any other external solution.

My guess is that my functions inside doStuff function are still running and that's why pause and resume works only once.

Is there a way to clear these functions after I have clicked them once? Or am I trying to do this in a totally wrong way? Help is appreciated. :)


Source: (StackOverflow)

App always starts fresh from root activity instead of resuming background state (Known Bug)

I am facing exactly the problem mentioned in these links:

http://code.google.com/p/android/issues/detail?id=2373

http://groups.google.com/group/android-developers/browse_thread/thread/77aedf6c7daea2ae/da073056831fd8f3?#da073056831fd8f3

http://groups.google.com/group/android-developers/browse_thread/thread/2d88391190be3303?tvc=2

I have a simple root activity with the LAUNCHER and MAIN intents and nothing else. I start another activity with has no flags or anything extra in the manifest whatsoever.

I launch the app (root activity) and from there start the 2nd activity. On pressing the Home button the task goes to the background. On launching the app again (from Launcher or from holding the Home button for recent apps) it starts a new instance of the root activity on top of the existing stack.

If I press the back button, the new "root" activity closes and the old 2nd activity is visible, which means its launching the root activity in the same task instead of bring the task to the foreground.

To counter this I made the root activity's launch Mode singleTask. Now when I press home and launch the app again, it clears the activities above the old root task and brings the old root task to the foreground instead of just bringing the entire old task with the 2nd activity on top to the front. Note that the old root task still retains its application state, which means it wasn't a new instance, but the the higher activities had been killed.

Why isn't the problem fixed by now? It's been almost a year! It even occurs on other applications downloaded from the market. The manual install method has no effect for me, it still launches the same way.


Source: (StackOverflow)

Prevent "Resume" for my Cocoa application?

I love the new "Resume" feature in Lion. After a restart window size and position is exactly how you left it. But during development this is a bit annoying. If I resize a window in the Interface Builder and restart my application it doesn't have the new size but the old size.

In the past you had to set the AUTOSAVE property to get this kind of behavior but with Resume it all happens automatically. Can I disable resume for my application somehow?


Source: (StackOverflow)

pausing and resuming child activities in ActivityGroup

I am making a first try att creating a custom ActivityGroup. I am getting everything working except the activity lifecycle methods of the groups child activities. How can i call the onResume/onPause methods in my child activities when they enter/exit focus?

I know the tabActivity does this but i cannot find how when looking through the code.

Thanks in advance!


Source: (StackOverflow)

how to play or resume music of another music player from my code?

In my android app I want to play or resume the played music after a paused it. I got my app to pause the music by sending a broadcast, but I can't get it to play or resume the music.

here is the code to pause

    Intent i = new Intent("com.android.music.musicservicecommand");
            i.putExtra("command", "pause");
            sendBroadcast(i);

how can it be done?

Edit: sorry, I wrote "resume" instead of "pause"


Source: (StackOverflow)

Java: resume Download in URLConnection

Hi
I wrote a program that downloads some files from some servers.
Currently program works properly.
But I want to add resume support to it.
I'm doing it like this But the result file is corrupted:

....

File fcheck=new File(SaveDir+"/"+filename);
if(resumebox.isSelected() && fcheck.exists()){
    connection.setRequestProperty("Range", "Bytes="+(fcheck.length())+"-");
}

connection.setDoInput(true);
connection.setDoOutput(true);

BufferedInputStream in = new BufferedInputStream (connection.getInputStream()); 

pbar.setIndeterminate(false);
pbar.setStringPainted(true);

java.io.FileOutputStream fos ;
if(resumebox.isSelected()){
    if(fcheck.exists()){
        if(connection.getHeaderField("Accept-Ranges").equals("bytes")){
            fos = new java.io.FileOutputStream(SaveDir+"/"+filename,true);
        }else{
            fos = new java.io.FileOutputStream(SaveDir+"/"+filename);
        }
    }else{
        fos = new java.io.FileOutputStream(SaveDir+"/"+filename);
    }
}else{
    fos = new java.io.FileOutputStream(SaveDir+"/"+filename);
}

....

I'm Testing it on a server that I know supports resume.
I downloaded some bytes.(72720)
Then Tried to resume it.
Then I opened file with a Hex editor , At offset 72720 the first Bytes are repeated:
Bytes 0-36: FLV.............«..........onMetaData
Bytes 72720-72756: FLV.............«..........onMetaData
It Starts download from the begining!
While when I do it by wget it does correctly and responses by Content-Range field!
Server responses with "302 FOUND" and a "206 Partial Content" in wget log.
Can "302 FOUND" cause the problem?

What is the problem ?
Thanks.


Source: (StackOverflow)