2016-07-19 3 views
-2

트위터 클라이언트를 만들려고하는데이 시나리오가 붙어 있습니다. 사용자에게 앱을 승인하도록 안내하는 시작 화면에 버튼이 있습니다. 이 버튼은 트위터 인증 페이지를 호출하고 URL을 반환합니다. onNewIntent 메서드를 호출하여 URL 세부 정보를 캡처하고 저장해야합니다. 어떤 이유로 인해 메소드가 호출되지 않습니다. 도와주세요.onNewIntent 메서드가 호출되지 않습니다.

android:launchMode="singleTop" 

도 작동하지 않습니다.

onNewInte 이후에서 onCreate 방법

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 


    //Enabling strict mode 
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); 

    StrictMode.setThreadPolicy(policy); 

    //get the preferences for the app 
    nicePrefs = getSharedPreferences("WolfyPref", 0); 


    //find out if the user preferences are set 
    if(nicePrefs.getString("user_token", null)==null) { 

     setContentView(R.layout.activity_main); 

     //no user preferences so prompt to sign in 

     niceTwitter = new TwitterFactory().getInstance(); 
     niceTwitter.setOAuthConsumer(TWIT_KEY,TWIT_SECRET); 
     //try to get request token 
     try 
     { 
      //get authentication request token 
      niceRequestToken = niceTwitter.getOAuthRequestToken(TWIT_URL); 
     } 
     catch(TwitterException te) { Log.e(LOG_TAG, "TE " + te.getMessage()); } 

     FloatingActionButton fab = (FloatingActionButton)findViewById(R.id.fab); 
     fab.setOnClickListener(this); 
    } 
    else 
    { 
     //user preferences are set - get timeline 
     setupTimeline(); 
    } 


/* Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
    setSupportActionBar(toolbar);*/ 


} 

온 클릭

public void onClick(View v) { 
    //find view 
    switch(v.getId()) { 
     //sign in button pressed 
     case R.id.fab: 
      //take user to twitter authentication web page to allow app access to their twitter account 
      String authURL = niceRequestToken.getAuthenticationURL(); 
      startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(authURL))); 
      break; 

     default: 
      break; 
    } 
} 

onNewIntent

@Override 
protected void onNewIntent(Intent intent) { 
    super.onNewIntent(intent); 
    //get the retrieved data 
    Uri twitURI = intent.getData(); 
    //make sure the url is correct 
    if(twitURI!=null && twitURI.toString().startsWith(TWIT_URL)) 
    { 
     //is verifcation - get the returned data 
     String oaVerifier = twitURI.getQueryParameter("oauth_verifier"); 
     //attempt to retrieve access token 
     try 
     { 
      //try to get an access token using the returned data from the verification page 
      AccessToken accToken = niceTwitter.getOAuthAccessToken(niceRequestToken, oaVerifier); 

      //add the token and secret to shared prefs for future reference 
      nicePrefs.edit() 
        .putString("user_token", accToken.getToken()) 
        .putString("user_secret", accToken.getTokenSecret()) 
        .apply(); 

      //display the timeline 
      setupTimeline(); 
     } 
     catch (TwitterException te) 
     { Log.e(LOG_TAG, "Failed to get access token: " + te.getMessage()); } 

    } 
} 

NT 메서드가 호출되지 않습니다.이 화면이 나타납니다.

enter image description here

답변

0

onNewIntent는 플래그 활동에 대해 호출 될 것이다 'singleTop'이 활동은 이미 가기 backstack의 상단에 존재하는 경우에만 가능합니다. 귀하의 경우 처음으로 활동을 시작한 것이므로 onNewIntent의 인보 케이션이 없습니다.

자세한 내용은 this을 참조하십시오.

+0

이 문제를 해결하려면 여기를 어떻게해야합니까? – sreeragnk

+0

WelcomeActivity 및 AuthorizeActivity가있는 경우 인 텐트로 초를 시작하고 모든 데이터를 '추가 기능'을 통해 전달하십시오. 그런 다음 onCreate 메소드의 두 번째 활동에서 추가 기능을 검색하고 원하는대로 수행하십시오. –

+0

동일한 코드가 이전에 제대로 작동했습니다. 나는 뭔가를했고 더 이상 일하지 않습니다. 클래스 파일을 더 이상 추가 할 수 없습니다. 같은 코드로 작업해야합니다. – sreeragnk

관련 문제