package com.example.sampleflagintentsjh;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBarActivity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
Button showBtn;
TextView txtMsg;
String msg;
/** 요청 코드 정의 **/
public static final int REQUEST_CODE_ANOTHER = 1001;
/** 시작 횟수 **/
public static int startCount = 0;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container,
false);
showBtn = (Button)rootView.findViewById(R.id.showBtn);
txtMsg = (TextView)rootView.findViewById(R.id.txtMsg);
showBtn.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
Intent receivedIntent = getIntent();
startCount = receivedIntent.getIntExtra("startCount", 0);
// 텍스트뷰에 startCount 값을 보여줍니다.
msg = "전달된 startCount : " + startCount;
txtMsg.setText(msg);
}
});
// 전달받은 인텐트를 처리합니다.
Intent receivedIntent = getIntent();
startCount = receivedIntent.getIntExtra("startCount", 0);
// 텍스트뷰에 startCount 값을 보여줍니다.
msg = "전달된 startCount : " + startCount;
txtMsg.setText(msg);
return rootView;
}
protected void onNewIntent(Intent intent) {
// 전달받은 인텐트를 처리합니다.
Intent receivedIntent = getIntent();
startCount = receivedIntent.getIntExtra("startCount", 0);
// 텍스트뷰에 startCount 값을 보여줍니다.
msg = "전달된 startCount : " + startCount;
txtMsg.setText(msg);
super.onNewIntent(intent);
}
}
}
현재 독학으로 공부를 하고있는데 안드로이드가 킷캣으로 업그레이드 되면서
빨강글씨로 된 getIntent()부분과 onNewIntent 이 부분에서 에러가 뜨는데 어떻게 해야 하나요?
갑자기 업그레이드 되면서 바뀌니까 난감하네요-.-
꼭 답변 부탁드립니다.