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

안드로이드 활성화 문제

0 추천
<카운터가 다되면 잠금화면으로 가는 액티비티 2개로 이루어진 소스인데요
 카운트를 실행하고 홈키를 눌러서 다른 작업을 하다가 시간이 다되면 액티비티2(잠금화면)으로 가는데요
전화올떄처럼 프로그램이 어떤작업을 하고 있어도 액티비티2(잠금화면)으로 바뀌는거요>
부탁드립니다.
 
이게 카운터 소스구요
 
여기서 시간설정을해서 1시간 설정 하면 1시간이 줄어듭니다. 0이 되면 다음 액티비티로 넘어가는데요


  
  Bundle bundle = getIntent().getExtras();
  int value = bundle.getInt("some_key");
  int value2 = bundle.getInt("some_key2");
  int time;
  
        tv  = (TextView)findViewById(R.id.tv);
        tv.setText("value"); // startting from 10.
        time = value*60000+ value2*1000;
        final MyCounter timer = new MyCounter(time,1000);
        timer.start();
}
 @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
 @SuppressLint("NewApi")
 public class MyCounter extends CountDownTimer{
  
        public MyCounter(long millisInFuture, long countDownInterval) {
            super(millisInFuture, countDownInterval);
        }
 
        @SuppressLint("NewApi")
  @Override
        public void onFinish() {
            System.out.println("Timer Completed.");
            tv.setText("Timer Completed.");
           
            Intent intent = new Intent(CountActivity.this, Jamgeum1Activity.class);
   startActivity(intent);
            finish();
         //android.os.Process.killProcess(android.os.Process.myPid() );
        }
 
        @Override
        public void onTick(long millisUntilFinished) {
         tv.setText((millisUntilFinished/60000)+"시"+(millisUntilFinished%60000/1000)+"분");
         if((millisUntilFinished%60000/1000)==30)
         {
         Notification.Builder notiBuilder = new Notification.Builder(getApplicationContext());
            notiBuilder.setSmallIcon(R.drawable.icon);
            notiBuilder.setContentTitle("스마트폰 중독 탈출 앱");
            notiBuilder.setContentText("30분 남았습니다.");
            Context context = getApplicationContext();
            Toast.makeText(context, "30분 남았습니다.", Toast.LENGTH_SHORT).show();
            Notification noti = notiBuilder.build();
          
            //------------------------------------------------------------------
            // Notify
          
            NotificationManager notiManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
            notiManager.notify(0, noti);
         }
            System.out.println("Timer  : " + (millisUntilFinished/1000));
        }
    }
}
 

  
  DigitalClock dc = (DigitalClock) findViewById(R.id.digitalClock1);
  ImageButton btn = (ImageButton) findViewById(R.id.imageButton1);
  btn.setOnClickListener(new OnClickListener()
  {
   public void onClick(View v){
        startActivity(new Intent("android.intent.action.DIAL",
      Uri.parse("tel:")));
    
  }
 });
  ImageButton btn2 = (ImageButton) findViewById(R.id.imageButton2);
  btn2.setOnClickListener(new OnClickListener()
  {
   public void onClick(View v){
    startActivity(new Intent("android.intent.action.SENDTO",
      Uri.parse("sms:")));
    
  }
 });
        tv  = (TextView)findViewById(R.id.tv);
        tv.setText("10"); // startting from 10.
       // time = value*60000+ value2*1000;
        final MyCounter timer = new MyCounter(10000,1000);
        timer.start();
}
 public class MyCounter extends CountDownTimer{
  
        public MyCounter(long millisInFuture, long countDownInterval) {
            super(millisInFuture, countDownInterval);
        }
 
        @Override
        public void onFinish() {
            System.out.println("Timer Completed.");
            tv.setText("Timer Completed.");
            Intent intent = new Intent(Jamgeum1Activity.this, MainActivity.class);
   startActivity(intent);
            finish();
         //android.os.Process.killProcess(android.os.Process.myPid() );
        }
 
        @Override
        public void onTick(long millisUntilFinished) {
          //tv.setText((millisUntilFinished/60000)+"시"+(millisUntilFinished%60000/1000)+"분");
         tv.setText(millisUntilFinished/1000+"");
            System.out.println("Timer  : " + (millisUntilFinished/1000));
        }
    }
}
 

 

 

친구영웅 (160 포인트) 님이 2013년 9월 15일 질문

답변 달기

· 글에 소스 코드 보기 좋게 넣는 법
· 질문에 대해 추가적인 질문이나 의견이 있으면 답변이 아니라 댓글로 달아주시기 바랍니다.
표시할 이름 (옵션):
개인정보: 당신의 이메일은 이 알림을 보내는데만 사용됩니다.
스팸 차단 검사:
스팸 검사를 다시 받지 않으려면 로그인하거나 혹은 가입 하세요.
...