tools:context link to multiple Activities

1.9k views Asked by At

I have read about tools:context and found it pretty useful while development, as it helps me to know which activities I have used current Xml.

My Problem is:

I have 2 Activities, using same Xml file(Reusing same layout.xml file), but I am unable to link both using tools:context

How can I link 2 Activities using tools:context in Xml?

I have tried:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    tools:context="com.example.mytestapp.MainActivity,com.example.mytestapp.Main2Activity">

    <!-- Other Layouts Here -->

</RelativeLayout>

This gives me Red lines

Also tried using:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:tools2="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    tools:context="com.example.mytestapp.MainActivity"
    tools2:context="com.example.mytestapp.Main2Activity">

    <!-- Other Layouts Here -->

</RelativeLayout>

This doesn't give Red lines but when I run them, I get following error:

Error:(2) error: duplicate attribute.
Error:(2) duplicate attribute.
0

There are 0 answers