public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        EditText edit = findViewById(R.id.edit);
        Button btn = findViewById(R.id.btn);
        TextView view = findViewById(R.id.view);

        btn.     setOnClickListener(v -> {
            String str = edit.getText().toString();
            view.postDelayed(new Runnable() {
                int i = 0;

                @Override
                public void run() {
                    if (i < str.length()) {
                        view.append(str.charAt(i++) + "");
                        view.postDelayed(this, 1000);
                    }
                }
            }, 1000);
        });
    }
}

编写一个程序，实现播放音乐，能播放，暂停和重播。
public class MainActivity extends AppCompatActivity {

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

        // 重点: MediaPlayer.create(this, R.raw.music), start, pause, seekTo
        MediaPlayer player = MediaPlayer.create(this, R.raw.music);
        Button playBtn = findViewById(R.id.playBtn);
        Button pauseBtn = findViewById(R.id.pauseBtn);
        Button replayBtn = findViewById(R.id.replayBtn);

        playBtn.setOnClickListener(v->player.start());
        pauseBtn.setOnClickListener(v->player.pause());
        replayBtn.setOnClickListener(v->{
            player.seekTo(0);
            player.start();
        });
    }
}

编写一个程序，实现在状态栏提示有新消息，展开状态栏可查看消息，点击消息时弹出详细信息界面。MAIN//
public class MainActivity extends AppCompatActivity {

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

        // 创建通知信道
        NotificationChannel channel = new NotificationChannel("id", "name", NotificationManager.IMPORTANCE_DEFAULT);
        NotificationManager manager = getSystemService(NotificationManager.class);
        manager.createNotificationChannel(channel);

        Button sendBtn = findViewById(R.id.sendBtn);
        sendBtn.setOnClickListener(v->{
            // 点击通知跳转
            Intent it = new Intent(this, DetailActivity.class);
            it.putExtra("content", "一条通知");
            PendingIntent pit = PendingIntent.getActivity(this, 0, it, PendingIntent.FLAG_IMMUTABLE);

            // 创建通知
            NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "id")
                    .setSmallIcon(android.R.drawable.ic_dialog_info)
                    .setContentText("一条通知")
                    .setContentIntent(pit);

            // 发送通知
            manager.notify(0, builder.build());
        });

    }
}



DEtail//
public class DetailActivity extends AppCompatActivity{

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

        TextView contentView = findViewById(R.id.contentView);
        contentView.setText(getIntent().getStringExtra("content"));
    }
}


广播：
app1发送广播，app2接收发送的广播，并发送一个消息，当点击消息时，打开app3中的一个Activity，并显示“你好，广播”
APP1
  public class MainActivity extends AppCompatActivity {

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

        Button sendBtn = findViewById(R.id.sendBtn);
        sendBtn.setOnClickListener(v->{
            Intent it = new Intent();
            it.setComponent(new ComponentName("com.example.app2", "com.example.app2.MyReceiver"));
            sendBroadcast(it);
        });
    }
}


APP2  MyReceiver//
 public class MyReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {


        NotificationChannel channel = new NotificationChannel("id", "name", NotificationManager.IMPORTANCE_DEFAULT);
        NotificationManager manager = context.getSystemService(NotificationManager.class);
        manager.createNotificationChannel(channel);

        Intent it = new Intent();
        it.setComponent(new ComponentName("com.example.app3", "com.example.app3.ShowActivity"));
        PendingIntent pit = PendingIntent.getActivity(context, 0, it, PendingIntent.FLAG_IMMUTABLE);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(context, "id")
                .setSmallIcon(android.R.drawable.ic_dialog_info)
                .setContentText("点击跳转到app3")
                .setContentIntent(pit);
        manager.notify(0, builder.build());
    }
}

NOTIFYactivity//
public class NotifyActivity extends AppCompatActivity {

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


    }
}

APP3  show//
 <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="你好, 广播!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
