2017-02-24 226 views
-2

晚上好,我將開始一個活動的主要佈局,第一次在智能手機上開始的應用程序,我該怎麼辦? 這是我的主要活動...當我的apo開始時,您可以看到我的activity_main選擇通知從firebase收回,當我設置通知時,應用程序將您重定向到另一個activity_mainweb當我放置webview時,我想看到只有在第一次第一activity_main佈局第一次開通智能手機應用程序的活動

公共類MainActivity擴展AppCompatActivity {

private static final String TAG = "MainActivity"; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    // If a notification message is tapped, any data accompanying the notification 
    // message is available in the intent extras. In this sample the launcher 
    // intent is fired when the notification is tapped, so any accompanying data would 
    // be handled here. If you want a different intent fired, set the click_action 
    // field of the notification message to the desired intent. The launcher intent 
    // is used when no click_action is specified. 
    // 
    // Handle possible data accompanying notification message. 
    // [START handle_data_extras] 
    if (getIntent().getExtras() != null) { 
     for (String key : getIntent().getExtras().keySet()) { 
      Object value = getIntent().getExtras().get(key); 
      Log.d(TAG, "Key: " + key + " Value: " + value); 
     } 
    } 
    // [END handle_data_extras] 

    Button subscribeButton = (Button) findViewById(R.id.subscribeButton0); 
    subscribeButton.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      // [START subscribe_topics] 
      FirebaseMessaging.getInstance().subscribeToTopic("INTERIORDESIGN150H"); 
      // [END subscribe_topics] 

      // Log and toast 
      String msg = getString(R.string.msg_subscribed); 
      Log.d(TAG, msg); 
      Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show(); 
     } 
    }); 

    Button subscribeButton1 = (Button) findViewById(R.id.subscribeButton1); 
    subscribeButton1.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      // [START subscribe_topics] 
      FirebaseMessaging.getInstance().subscribeToTopic("INTERIORDESIGN300H"); 
      // [END subscribe_topics] 

      // Log and toast 
      String msg = getString(R.string.msg_subscribed); 
      Log.d(TAG, msg); 
      Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show(); 
     } 
    }); 




    Button subscribeButton2= (Button) findViewById(R.id.subscribeButton2); 
    subscribeButton2.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      // [START subscribe_topics] 
      FirebaseMessaging.getInstance().subscribeToTopic("GARDENDESIGN150H"); 
      // [END subscribe_topics] 

      // Log and toast 
      String msg = getString(R.string.msg_subscribed); 
      Log.d(TAG, msg); 
      Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show(); 
     } 
    }); 



    Button subscribeButton3 = (Button) findViewById(R.id.subscribeButton3); 
    subscribeButton3.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      // [START subscribe_topics] 
      FirebaseMessaging.getInstance().subscribeToTopic("GARDENDESIGN300H"); 
      // [END subscribe_topics] 

      // Log and toast 
      String msg = getString(R.string.msg_subscribed); 
      Log.d(TAG, msg); 
      Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show(); 
     } 
    }); 




    Button subscribeButton4 = (Button) findViewById(R.id.subscribeButton4); 
    subscribeButton4.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      // [START subscribe_topics] 
      FirebaseMessaging.getInstance().subscribeToTopic("VISUALDESIGN150H"); 
      // [END subscribe_topics] 

      // Log and toast 
      String msg = getString(R.string.msg_subscribed); 
      Log.d(TAG, msg); 
      Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show(); 
     } 
    }); 




    Button subscribeButton5 = (Button) findViewById(R.id.subscribeButton5); 
    subscribeButton5.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      // [START subscribe_topics] 
      FirebaseMessaging.getInstance().subscribeToTopic("PRODUCTDESIGN150H"); 
      // [END subscribe_topics] 

      // Log and toast 
      String msg = getString(R.string.msg_subscribed); 
      Log.d(TAG, msg); 
      Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show(); 
     } 
    }); 



    Button subscribeButton6 = (Button) findViewById(R.id.subscribeButton6); 
    subscribeButton6.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      // [START subscribe_topics] 
      FirebaseMessaging.getInstance().subscribeToTopic("MOTIONDESIGN150H"); 
      // [END subscribe_topics] 

      // Log and toast 
      String msg = getString(R.string.msg_subscribed); 
      Log.d(TAG, msg); 
      Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show(); 
     } 
    }); 



    Button subscribeButton7 = (Button) findViewById(R.id.subscribeButton7); 
    subscribeButton7.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      // [START subscribe_topics] 
      FirebaseMessaging.getInstance().subscribeToTopic("GRAPHICDESIGN150H"); 
      // [END subscribe_topics] 

      // Log and toast 
      String msg = getString(R.string.msg_subscribed); 
      Log.d(TAG, msg); 
      Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show(); 
     } 
    }); 
    Button Button = (Button) findViewById(R.id.subscribeButton0); 

    Button.setOnClickListener(new View.OnClickListener(){ 
     public void onClick(View v){ 
      startActivity(new Intent(MainActivity.this, MainActivityweb.class)); 
     } 
    }); 
    Button Button1 = (Button) findViewById(R.id.subscribeButton1); 

    Button1.setOnClickListener(new View.OnClickListener(){ 
     public void onClick(View v){ 
      startActivity(new Intent(MainActivity.this, MainActivityweb.class)); 
     } 
    }); 
    Button Button2 = (Button) findViewById(R.id.subscribeButton2); 

    Button2.setOnClickListener(new View.OnClickListener(){ 
     public void onClick(View v){ 
      startActivity(new Intent(MainActivity.this, MainActivityweb.class)); 
     } 
    }); 
    Button Button3 = (Button) findViewById(R.id.subscribeButton3); 

    Button3.setOnClickListener(new View.OnClickListener(){ 
     public void onClick(View v){ 
      startActivity(new Intent(MainActivity.this, MainActivityweb.class)); 
     } 
    }); 
    Button Button4 = (Button) findViewById(R.id.subscribeButton4); 

    Button4.setOnClickListener(new View.OnClickListener(){ 
     public void onClick(View v){ 
      startActivity(new Intent(MainActivity.this, MainActivityweb.class)); 
     } 
    }); 
    Button Button5 = (Button) findViewById(R.id.subscribeButton5); 

    Button5.setOnClickListener(new View.OnClickListener(){ 
     public void onClick(View v){ 
      startActivity(new Intent(MainActivity.this, MainActivityweb.class)); 
     } 
    }); 
    Button Button6 = (Button) findViewById(R.id.subscribeButton6); 

    Button6.setOnClickListener(new View.OnClickListener(){ 
     public void onClick(View v){ 
      startActivity(new Intent(MainActivity.this, MainActivityweb.class)); 
     } 
    }); 
    Button Button7 = (Button) findViewById(R.id.subscribeButton7); 

    Button7.setOnClickListener(new View.OnClickListener(){ 
     public void onClick(View v){ 
      startActivity(new Intent(MainActivity.this, MainActivityweb.class)); 
     } 
    }); 
    } 
} 
+2

非常不清楚你在問什麼。 – Kuffs

+0

爲什麼?這是一個簡單的問題,只有當應用程序第一次在智能手機上啓動時,我必須打開我的一個佈局活動。 –

+1

爲什麼?因爲這個問題看起來像是由一個糟糕的翻譯應用程序處理,沒有任何意義。 – Kuffs

回答

1

您需要使用SharedPrefs跟蹤無論是國內首家推出並重定向到另一個佈局,如果它是

private static final String KEY_HAS_BEEN_LAUNCHED_BEFORE = "KEY_HAS_BEEN_LAUNCHED"; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); 
    boolean hasBeenLaunchedBefore = prefs.getBoolean(KEY_HAS_BEEN_LAUNCHED_BEFORE , false); 
    setContentView(hasBeenLaunchedBefore ? R.layout.normal_layout 
             : R.layout.first_launch_layout); 
    if (!hasBeenLaunchedBefore) { 
     //after the first launch, record that it's been seen 
     final SharedPreferences.Editor editor = prefs.edit(); 
     editor.putBoolean(KEY_HAS_BEEN_LAUNCHED_BEFORE , true); 
     editor.apply(); 
    } 
} 
+0

你現在可以檢查我的問題嗎? –

+1

他爲你寫了整個代碼片段,你還想要更多什麼?只需複製並粘貼即可。 – Cottontree

+0

它不是功能 –

相關問題