Recent Posts
Recent Comments
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
관리 메뉴

Dev.

Notify 터치시 현재 실행중 히스토리로 이동하기 본문

Android

Notify 터치시 현재 실행중 히스토리로 이동하기

Pppdw 2015. 7. 21. 14:44

개발시 상당히 애를 먹었던 구간이라 글로 남겨본다.

노티를 터치했을때 가장최근 즉 히스토리자체를 불러오는 것을 구현해야 했는데,

PendingIntent에 아무리 Intent를 달아봣자 새로운페이지가 실행되거나,

플래그조절로 히스토리가 날아가고 처음부터 다시뜨는 등 상당히 까다로운 구간이었다.

(위에서 설명하는 기능은 백그라운드 에서 안드로이드 홈키를 꾹눌렀을때, 사용했던(히스토리가 남아있는) 앱이 나오고

해당 앱을 터치시 액티비티 스택을 유지한체 가장 최근의 히스토리로 날아가고 그위치부터 앱이 실행되게 된다. 

그 기능을 말하는 것.)

 
/**노티 터치액션 설정 부**/
/**BroadCastReceiver Name은 com.example.test.testreceiver 로 가정**/
Notification n = new Notification();
n.when = System.currentTimeMillis();
n.flags = Notification.FLAG_ONGOING_EVENT;
Intent i = new Intent("com.example.test.testreceiver");
PendingIntent pi = PendingIntent.getBroadcast(mContext, 0, i, PendingIntent.FLAG_CANCEL_CURRENT);
		n.setLatestEventInfo(mContext, getAppName(), text, pi);


/**해당 BroadCastReceiver Class**/
public class NotiBroadCastReciever extends BroadcastReceiver {
 
    @Override
    public void onReceive(Context context, Intent intent) {
         
        String name = intent.getAction();
         
        if(name.equals("com.example.test.testreceiver")){
    		ActivityManager am = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
    		List tasks =am.getRunningTasks(30);
    		if(!tasks.isEmpty()) {
    			int tasksSize = tasks.size();
    			for(int i = 0; i < tasksSize;  i++) {
    						RunningTaskInfo taskinfo = tasks.get(i);
    						if(taskinfo.topActivity.getPackageName().equals("팝 시켜야할 패키지 이름")) {
    							am.moveTaskToFront(taskinfo.id, 0);
    						}
    			}
    		}
        }
    }
}

/**AndroidManifest.xml**/

            
                
            	
            
          

리시버를 하나 구현하니 의외로 간단히 끝났다.

진짜 패키지를 띄우는 모든종류의 삽질을 다해본 것 같았지만, 답은 moveTaskToFront객체에 있었다.

해당 앱이 쫌 까다로운부분이 많아서 이런식으로 할 수 밖에없었지만, 다른 방법이있다면 뭐 그방법을 이용해도..

어쨋든 이런걸로 고통받는 개발자 분들에게 도움이 되었으면 좋겠다.

Comments