마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

GCM 수신 후 mainactivity에 있는 webview URL 변경이 가능할까요?

0 추천
public class GcmIntentService extends IntentService {
....
    public GcmIntentService() {
        super("GcmIntentService");
    }

    @Override
    protected void onHandleIntent(Intent intent) {
        Bundle extras = intent.getExtras();
        GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
        // The getMessageType() intent parameter must be the intent you received
        // in your BroadcastReceiver.
        String messageType = gcm.getMessageType(intent);

        if (!extras.isEmpty()) {
            if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {

                Context context = getApplicationContext();
                Intent in = new Intent(context, MainActivity.class);// change the context and activity name.
                in.putExtras(intent.getExtras());
                in.putExtra("url","http://www.daum.net");
                in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(in); // change the context name.
...
                Log.i(TAG, "Received: " + extras.toString());
            }
        }
        // Release the wake lock provided by the WakefulBroadcastReceiver.
        GcmBroadcastReceiver.completeWakefulIntent(intent);
    }
...
}

 

GCM 수신 후 MainActivity.class에 있는 webview의 URL을 원하는 주소로 변경하려고 합니다.

 

                Context context = getApplicationContext();
                Intent in = new Intent(context, MainActivity.class);// change the context and activity name.
                in.putExtras(intent.getExtras());
                in.putExtra("url","http://www.daum.net");
                in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(in); // change the context name.

이렇게 하려고 하니 기존의 MainActivity.class에 접근하는 것이 아니라 새로운 MainActivity.class가 뜨게 되네요. 기존의 MainActivity.class에 접근해서 webview의 URL을 제어할 수는 없을까요?

오리선생 (120 포인트) 님이 2015년 10월 22일 질문

1개의 답변

0 추천
setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

Intent Flag가 잘못되어있네요.

일단은 single_top 정도로도 동작할것 같긴한데

새로생성하는 것 말고 적절하게 골라서 주세요
홍월령 (4,240 포인트) 님이 2015년 10월 22일 답변
...